Debug Core-Dump with GDB for DS

Debug Core-Dump with GDB for Linked-List or any DS traversal

There are instances of core-dump with huge Linked-List data.

The challenge is How-To fetch the Linked-List data and analyzes the data, as manually it’s not feasible if list contains few lakh entries.

The problem is solved by writing GDB script, specific to your Data Structure and output the Linked-List data to a file.

You could write logic what data to fetch and what to ignore based on conditions in GDB script.

This is applicable to any Data-Structure.

1. Create a GDB Script: Specific to you DS (See example below).

2. Invoke GDB:

gdb64 /usr/bin/myApp /core/core.myApp.5957

3. Source GDB script:

source list_head.gdb

4. Backtrace: bt

5. Go to target frame: up up

6. Invoke GDB script: p_list_head 0x4f54c50 [Address of head node of linked list]

7. See the Output: temp.txt

GDB Script: list_head.gdb

-------------------------------------------------------------------------------------------------

#Example for list_head traversal.

define p_list_head

set $list = ($arg0)

# Set logging off on console of gdb

set logging redirect off

# Set logging to file

set logging file temp.txt

# Disable the pagination prompt “Type <return> to continue, or q <return> to quit”

set pagination off

# Set logging on

set logging on

while ($list != 0)

if((((client_task) * $list)->client_id) == 2049)

#p (list_head) * $list

#p (client_task) * $list

p (((client_task) * $list)->client_id)

p (((client_task) * $list)->client_flags)

p (((client_task) * $list)->client_num)

set $list = (((list_head) * $list)->next)

else

set $list = (((list_head) * $list)->next)

end

end

# Reset all settings to default

set logging redirect on

set pagination on

set logging off

end

document p_list_head

p_list_head <list>: Dumps the strings in a list_head

end

-------------------------------------------------------------------------------------------------

Data Structures in Code

struct list_head {

struct list_head *next, *prev;

};

struct client_task {

uint64_t offset;

uint16_t client_id;

uint16_t client_flags;

uint8_t client_num;

}

-------------------------------------------------------------------------------------------------

References:

- http://johnnyjacob.wordpress.com/2009/07/07/gdb-scripting-short-article-for-internal-magazine/

- http://sourceware.org/gdb/wiki/FAQ

- http://madapvamshi.blogspot.in/2011/09/writing-gdb-scripts.html

- http://www.adacore.com/adaanswers/gems/gem-119-gdb-scripting-part-1/

- http://sourceware.org/gdb/current/onlinedocs/gdb/Logging-Output.html#Logging-Output

- http://www.robertames.com/blog.cgi/2011/03/

- http://stackoverflow.com/questions/2889639/using-gdb-with-gmp-variables

- http://users.ece.utexas.edu/~adnan/code.txt

- http://stackoverflow.com/questions/1707167/how-extract-text-from-gdb