How-To‎ > ‎

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)
   set $list = (((list_head) * $list)->next)
# Reset all settings to default
set logging redirect on
set pagination on
set logging off

document p_list_head
p_list_head <list>: Dumps the strings in a list_head


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;