Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created October 2, 2020 22:23
Show Gist options
  • Save gabrielschulhof/ece873cfba31e5be348b185650cf7857 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/ece873cfba31e5be348b185650cf7857 to your computer and use it in GitHub Desktop.
# Script to be used with gdb to trace changes to the maps file as Node.js
# performs mmaps.
import io
import os
import sys
import gdb
import shutil
import subprocess
class DiffMaps (gdb.Command):
"Compare maps file to previous run of the command"
def __init__(self):
super(DiffMaps, self).__init__(
"diffmaps",
gdb.COMMAND_RUNNING,
gdb.COMPLETE_NONE,
True)
def invoke(self, arg, from_tty):
orig = arg + "/000.maps"
new = arg + "/001.maps"
maps_file = "/proc/" + str(gdb.selected_inferior().pid) + "/maps"
# If this is the first time, the diff must be the whole original file.
if not os.path.isfile(orig):
io.open(orig, "w").close()
shutil.copyfile(maps_file, new)
diff = subprocess.Popen(["diff", "-u", orig, new])
diff.wait()
shutil.copyfile(new, orig)
gdb.flush()
DiffMaps()
set pagination off
set breakpoint pending on
set style enabled off
set environment NODE_ENV=production
source /home/nix/node-dtlb/run-ghost/scripts/diffmaps.script.py
define domaps
shell echo "*** Start Event ***"
shell echo "*** Initial diff **"
diffmaps /home/nix/node-dtlb/Ghost
shell echo "*******************"
bt 10
python gdb.execute('finish');
shell echo "*** Final diff ****"
diffmaps /home/nix/node-dtlb/Ghost
shell echo "*******************"
shell echo "*** End Event *****"
continue
end
start ./current/index
break mmap
commands
domaps
end
break munmap
commands
domaps
end
break mremap
commands
domaps
end
break madvise
commands
domaps
end
break mprotect
commands
domaps
end
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment