gdb - wlshiu/my_note GitHub Wiki
# generate object files
$ gcc -g -c test.c -o test.o
# get disassemble
$ objdump -D test.o
# addr2line with GDB
$ gdb test.o
gdb) list *(main+65)
#!/bin/bash
set -e
help()
{
echo -e "$0 [executable file]"
exit 1;
}
if [ $# != 1 ]; then
help
fi
exec_prog=$1
# cmd_gdb="gdb %s"
# cmd_gdb="gdb %s -tui"
LD_LIBRARY_PATH=./ns-3.28/build/:\
${LD_LIBRARY_PATH} \
./waf --run ${exec_prog} --command-template="gdb %s -tui"
################
# shell debug
# ./waf --shell
# $ cd build/debug/examples
# $ gdb first
#################
# gdb modify source path
# option: directory <dir>
#
# (gdb) list
# 6 ./Programs/python.c: No such file or directory.
# (gdb) directory /usr/src/python
# Source directories searched: /usr/src/python:$cdir:$cwd
# change source path prefix
# option: set substitute-path old_path new_path
#
# (gdb) list
# 6 ./Programs/python.c: No such file or directory.
# (gdb) set substitute-path /home/avd/dev/cpython /usr/src/python
# add path prefix during compiler
# gcc option: -fdebug-prefix-map = old_path = new_path
# $ make distclean # start clean
# $ ./configure CFLAGS="-fdebug-prefix-map=$(pwd)=/usr/src/python" --with-pydebug
# $ make -j
##############
# save/load breakpoints
# (gdb) save breakpoints ~/.breakpoints.rec
# (gdb) source ~/.breakpoints.rec
(gdb) set disassemble-next-line on
(gdb) show disassemble-next-line
Will give you results that look like this:
(gdb) stepi
0x000002ce in ResetISR () at startup_gcc.c:245
245 {
0x000002cc <ResetISR+0>: 80 b5 push {r7, lr}
=> 0x000002ce <ResetISR+2>: 82 b0 sub sp, #8
0x000002d0 <ResetISR+4>: 00 af add r7, sp, #0
(gdb) stepi
0x000002d0 245 {
0x000002cc <ResetISR+0>: 80 b5 push {r7, lr}
0x000002ce <ResetISR+2>: 82 b0 sub sp, #8
=> 0x000002d0 <ResetISR+4>: 00 af add r7, sp, #0
(gdb) set print pretty on
# arg0: List_t pointer
define dump_list
set $pHeadListItem=((List_t*)$arg0)->pxIndex
set $pCurListItem=$pHeadListItem
printf "Number of Tasks: %d\n\n", ((List_t*)$arg0)->uxNumberOfItems
if ((List_t*)$arg0)->uxNumberOfItems != 0
while 1
set $pTCB=((ListItem_t *)$pCurListItem)->pvOwner
printf "TASK: %s at 0x%08x\n", ((TCB_t*)$pTCB)->pcTaskName, $pTCB
printf "\n"
set $pCurListItem=$pCurListItem->pxNext
# get head item
if ((List_t*)$pCurListItem) == $pHeadListItem
loop_break
end
end
end
end
define dump_all_list
set $i=(sizeof(pxReadyTasksLists)/sizeof(pxReadyTasksLists[0]))-1
while $i >= 0
printf "\n---- ReadyTasksLists Prior %d \n", $i
dump_list &pxReadyTasksLists[$i]
set $i-=1
end
printf "\n---- DelayedTaskList1 \n"
dump_list &xDelayedTaskList1
printf "\n---- DelayedTaskList2 \n"
dump_list &xDelayedTaskList2
pxOverflowDelayedTaskList
# Pending
printf "\n---- PendingReadyList \n"
dump_list &xPendingReadyList
# Suspended
printf "\n---- SuspendedTaskList \n"
dump_list &xSuspendedTaskList
printf "\n---- OverflowDelayedTaskList \n"
dump_list pxOverflowDelayedTaskList
end