DEV Community

nullity
nullity

Posted on

gdb trick: automatically display local variables when stops

Add the following to ~/.gdbinit

define toggle-local
  if $toggle_hook_enabled == 0
    set $toggle_hook_enabled = 1
    define hook-stop
      info local
      printf "---------------------\n"
    end
    printf "display-local enabled.\n"
  else
    set $toggle_hook_enabled = 0
    define hook-stop
    end
    printf "display-local disabled.\n"
  end
end

set $toggle_hook_enabled = 0
Enter fullscreen mode Exit fullscreen mode

Usage

When in gdb session, use "toggle-local" to toggle it.

Why not always turn it on? If there are too many local variables, gdb would use pagination to show all the infomation, sometimes it's kind of annoying to press an addition Enter.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more