File: gdb-add-symbol-file

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (49 lines) | stat: -rwxr-xr-x 1,908 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

# Written by Gene Cooperman, Northeastern University
# WISHLIST:  that something like this goes into a future version of gdb

# This command will produce the add-symbol-file command with the
#  correct parameters, as needed by gdb, for loading debugging
#  information about a dynamic library (.so file)

test -z "$2" && echo Usage:  $0 PROCESS_PID LIBRARY_NAME_SUBSTRING
test -z "$2" && echo Note: '(gdb) info proc'
test -z "$2" && echo '    ' will print PROCESS_PID of process debugged by gdb
test -z "$2" && echo Then try: '(gdb) shell '$0 \
				PROCESS_PID LIBRARY_NAME_SUBSTRING
test -z "$2" && echo '    ' ... and paste the output of that command into gdb:
test -z "$2" && echo Hence: '(gdb) add-symbol-file ...'
test -z "$2" && exit

processPID=`pgrep -n $1`
processPID=$1
if ! test -e /proc/$processPID; then
  echo Process $processPID does not exist.  Please use existing proces.
  exit 1
fi
if test -z "`cat /proc/$processPID/maps | grep $2`"; then
  echo "**** Library $2 not found. "\
       "Do:  cat /proc/$processPID/maps  to see all libs."
  exit 1
fi

lib=`cat /proc/$processPID/maps | grep $2 | head -1 | \
	sed -e 's%[^/]*\(/.*\)%\1%'`

# libdmtcp.so can now have two r-x sections.  Why?
segAddr=`cat /proc/$processPID/maps | grep $lib | head -1 | grep r-xp | \
	sed -e 's%^\([0-9a-f]*\).*%0x\1%'`
segDataAddr=`cat /proc/$processPID/maps | grep $lib | grep rw-p | \
	sed -e 's%^\([0-9a-f]*\).*%0x\1%'`

textOffset=`readelf -S $lib | grep '\.text ' | \
	sed -e 's%^.*text[^0-9a-f]*[0-9a-f]* \([0-9a-f]*\).*%0x\1%'`
dataOffset=`readelf -S $lib | grep '\.data ' | \
	sed -e 's%^.*data[^0-9a-f]*[0-9a-f]* \([0-9a-f]*\).*%0x\1%'`
bssOffset=`readelf -S $lib | grep '\.bss ' | \
	sed -e 's%^.*bss[^0-9a-f]*[0-9a-f]* \([0-9a-f]*\).*%0x\1%'`

echo add-symbol-file $lib $(($segAddr + $textOffset)) \
	 -s .data $(($segDataAddr + $dataOffset)) \
	 -s .bss $(($segDataAddr + $bssOffset))