enrico.bacis
enrico.bacis

Reputation: 31514

Show gdb tui source code in another terminal

Is it possible to configure the gdb tui interface to show the source code in another terminal window (that I can put in another screen) or to simulate this behaviour using something like tmux?

Upvotes: 1

Views: 411

Answers (1)

matt
matt

Reputation: 5624

I don't know of any way to do this with gdb-tui specifically. A hack that works with normal gdb, or tui is to abuse the python prompt_hook function, overriding it to produce some effect based don the current file/line and return the normal prompt.

Below is an example which uses vim's +clientserver functionality to launch vim in a terminal, and follow along as the program counter changes.

import os
import subprocess

servername = "GDB.VI." + str(os.getpid());
terminal = "gnome-terminal"
terminal_arg ="-e"
editor = "vimx"
term_editor = "%s --servername %s" % (editor, servername)

subprocess.call([terminal, terminal_arg, term_editor])

def linespec_helper(linespec, fn):
  try:
    x = gdb.decode_line(linespec)[1][0]
    if x != None and x.is_valid() and x.symtab != None and x.symtab.is_valid():
      return fn(x) 
  except:
    return None

def current_file():
  return linespec_helper("*$pc", lambda x: x.symtab.fullname())

def current_line():
  return str(linespec_helper("*$pc", lambda x: x.line))

def vim_current_line_file():
  aLine = current_line()
  aFile = current_file()
  if aLine != None and aFile != None:
    subprocess.call([editor, "--servername", servername, "--remote", "+" + aLine, aFile])

old_prompt_hook = gdb.prompt_hook
def vim_prompt(current_prompt):
  vim_current_line_file()
  if old_prompt_hook != None:
    old_prompt_hook(current_prompt)
  else:
    None
gdb.prompt_hook = vim_prompt

Upvotes: 2

Related Questions