Some useful GDB scripts

Discussions and support about ChibiOS/RT, the free embedded RTOS.
faisal
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

Some useful GDB scripts

Postby faisal » Mon Apr 09, 2018 2:24 am

Prints out the trace buffer. I found this online somewhere, and fixed a bug it had to make it actually print the entire circular buffer:

Code: Select all

set $buflen = ch.dbg.trace_buffer.size
set $i=ch.dbg.trace_buffer.ptr-ch.dbg.trace_buffer.buffer-1
if $i < 0
    set $i = $buflen-1
end
set $ctr=0
while (ch.dbg.trace_buffer.buffer[$i].type != 0) && ($ctr < ($buflen-1))
   printf "%d,t=%d,rt=%d ", $ctr, ch.dbg.trace_buffer.buffer[$i].time, ch.dbg.trace_buffer.buffer[$i].rtstamp
   if ch.dbg.trace_buffer.buffer[$i].type == 1
        echo \ SWITCH \
        output ch.dbg.trace_buffer.buffer[$i].u.sw
    end
    if ch.dbg.trace_buffer.buffer[$i].type == 2
        echo \ ISR_ENTER \
        output ch.dbg.trace_buffer.buffer[$i].u.isr
    end
    if ch.dbg.trace_buffer.buffer[$i].type == 3
        echo \ ISR_LEAVE \
        output ch.dbg.trace_buffer.buffer[$i].u.isr
    end
    if ch.dbg.trace_buffer.buffer[$i].type == 4
        echo \ HALT \
        output ch.dbg.trace_buffer.buffer[$i].u.halt
    end
    if ch.dbg.trace_buffer.buffer[$i].type == 5
        echo \ USER \
        printf "%s,%s",(char*)ch.dbg.trace_buffer.buffer[$i].u.user.up1,(char*)ch.dbg.trace_buffer.buffer[$i].u.user.up2
    end
    echo \n
    if ($i == 0)
        set $i = $buflen-1
    else
        set $i = $i-1
    end
    set $ctr = $ctr + 1
end


Prints out all of the virtual timers:

Code: Select all

printf "Virtual Timers\n"
set $ctr = 0
set $p = ch.vtlist.next
while $p != &ch.vtlist
    printf "%d\tt=%d\tpar=0x%08x\tfunc= ", $ctr, $p->delta, $p->par
    output $p->func
    echo \n
    set $ctr = $ctr + 1
    set $p = $p->next
end


Other debug info, and available stack for all threads (excluding main):

Code: Select all

printf "Debug Info\n"
printf "isr_cnt=%d\tlock_cnt=%d\ttm_cal=%d\tpanic=", ch.dbg.isr_cnt, ch.dbg.lock_cnt, ch.tm.offset
output ch.dbg.panic_msg
echo \n\n

printf "Thread stack used\n"
set $filler = 0x5555555555555555
set $max_stack_size = 0xFFFF
set $tp = ch.rlist.newer
set $ctr = 0
while $tp != &ch.rlist
    printf "%d, %s, ", $ctr, $tp->name
    output $tp->wabase
    if strcmp($tp->name, "main") != 0
        set $unused = 0
        set $stk_ptr = (uint64_t *)$tp->wabase
        while (*$stk_ptr == $filler) && ($unused < $max_stack_size)
            set $stk_ptr = $stk_ptr + 1
            set $unused = $unused + sizeof(uint64_t)
        end
        printf ", unused stack = %d", $unused
    end
    echo \n
    set $ctr = $ctr + 1
    set $tp = $tp->newer
end

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Some useful GDB scripts

Postby Giovanni » Mon Apr 09, 2018 7:45 am

Hi,

Never used GDB directly this way, it looks very interesting. It would be nice to have some kind of console in Eclipse with a way to launch scripts from a collection.

Giovanni

faisal
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

Re: Some useful GDB scripts

Postby faisal » Mon Apr 09, 2018 2:13 pm

Giovanni wrote:Hi,

Never used GDB directly this way, it looks very interesting. It would be nice to have some kind of console in Eclipse with a way to launch scripts from a collection.

Giovanni


Yeah, necessity is the mother of invention ... I'm unable to use the ChibiOS eclipse debug plugin as I'm running Eclipse Neon.

You can launch the scripts from the debugger console by typing "source <path to script>"


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 41 guests