请不要回复我应该使用 ddd、nemiver、emacs、vim 或任何其他前端,我只是更喜欢 gdb,但希望看到它的输出与一些终端颜色。

有帮助吗?

解决方案

.gdbinit

你可以调整你的 ~/.gdbinit 有颜色。你可以用玛门的 .gdbinit 可以在这里找到:

https://github.com/gdbinit/gdbinit

您也可以根据需要调整它。我发现这个感谢 这个答案. 。以下是您可以获得的输出类型:

.gdbinit

GitHub 存储库也可用: https://github.com/gdbinit/Gdbinit

顺便说一句,同样的想法也 应用于LLDB.

GDB仪表板

遵循同样的理念, GDB仪表板 为 Python 中的 GDB 提供模块化可视化界面。

GDB Dashboard

(无效)行者

另一个类似的项目使用 GDB 的 Python 支持来提供更多的可扩展性,因此值得一试: https://github.com/dholm/voidwalker

@dholm 也提供了他自己的 .gdbinit 受到上一篇的启发。

(void)walker

密码数据库

一些项目提供了一组有用的功能,包括改进的显示。情况是这样的 PEDA 或者 密码数据库. 。后者给出了如下描述:

PEDA 替代品。本着我们好朋友的精神 windbg, pwndbg 发音为 pwnd-bag.

  • 速度
  • 弹性
  • 干净的代码

它提供了与 PEDA 类似的命令来支持调试和漏洞开发,以及更好的显示(尽管这不是该项目的主要焦点)。该软件仍在开发中,尚未正式发布。

pwndbg

沃特龙

项目 描述指出:

Voltron 是一个供黑客使用的可扩展调试器 UI。它允许您将在其他终端中运行的实用程序视图附加到调试器(LLDB或GDB),显示有用的信息,例如拆卸,堆栈内容,寄存器值等,同时仍然为您提供与您习惯的调试器CLI。

您可以修改您的 .gdbinit 自动集成它。然而,显示本身是在 GDB 之外的(例如在 tmux 拆分中)。

voltron

全球环境基金

全球环境基金 是另一种选择,其描述为:

它的目的主要由利用者和反向工程师使用,以使用Python API为GDB提供其他功能,以在动态分析和利用开发过程中提供帮助。

GEF

其他提示

这不是颜色,但考虑 gdb 的 文本图形用户界面. 。它对 gdb 的可用性产生了巨大的影响。

您可以通过以下方式启动它:

gdb -tui executable.out

截屏:

enter image description here

正如您所看到的,主要特点是:

  • 显示我们所在的源线以及周围的线
  • 显示断点

我知道你不想要一个前端。 但是 cgdb 如何与gdb非常接近, 它是textmode,但上面有一个源窗口,代码上有语法高亮。

通过使用颜色可以大大增强gdb的出现。这可以通过以下任何一种方法完成:

  1. 通过“设置提示”进行彩色提示。例如,将提示符加粗和红色:

    set prompt \ 033 [1; 31m(gdb)\ 033 [m

    或提示一个新的形状,粗体和红色:

    set prompt \ 033 [01; 31m \ n \ n ################################ #####> \ 033 [0米

  2. 通过挂钩着色命令

  3. “列表”的彩色语法高亮显示。命令。
  4. 所有示例均可在Michael Kelleher撰写的以下博客文章中找到:

    “Beautify GDB”, 2010年5月12日(通过archive.org)

    “实验性GDB语法高亮显示” ;,2010年5月15日(通过archive.org)

#into .gdbinit
shell mkfifo /tmp/colorPipe

define hook-disassemble
echo \n
shell cat /tmp/colorPipe | c++filt | highlight --syntax=asm -s darkness -Oxterm256 &
set logging redirect on
set logging on /tmp/colorPipe
end 

define hookpost-disassemble
hookpost-list
end 

define hook-list
echo \n
shell cat /tmp/colorPipe | c++filt | highlight --syntax=cpp -s darkness -Oxterm256 &
set logging redirect on
set logging on /tmp/colorPipe
end 

define hookpost-list
set logging off 
set logging redirect off 
shell sleep 0.1s
end 

define hook-quit
shell rm /tmp/colorPipe
end 

define re
hookpost-disassemble
echo \033[0m
end 
document re
Restore colorscheme
end 

警告:越野车。没有TUI支持,'用户模式'黑客。

找到主要部分此处 并修改了一下。需要突出,c ++ filt。如果颜色混乱,请发出重新命令。

cgdb gdb -tui

更好

整洁,我刚刚使用colout找到了这个hack: https:/ /github.com/nojhan/colout/blob/master/colout/example.gdbinit

我想强调如下:强调属于我的源文件(而不是库)的堆栈跟踪的行。

解决方案是使用gdb-python(在MSYS上;在Linux上通常是 gdb 附带内置的Python?),hook backtrace ,使用

python stack_trace = gdb.execute('backtrace', False, True')

然后使用Python的正则表达式处理 stack_trace ,然后将它们打印出来。大胆和其他颜色通过以下功能实现:

def term_style(*v):
    """1 is bold, 30--37 are the 8 colours, but specifying bold may also
    change the colour. 40--47 are background colours."""
    return '\x1B['+';'.join(map(str, v))+'m'

#Use like this:
print term_style(1) + 'This will be bold' + term_style(0) #Reset.
print term_style(1,30) + 'This will be bold and coloured' + term_style(0)
print term_style(1,30,40) + 'Plus coloured background' + term_style(0)

这给出了另一种很好的颜色组合配置。它使得回溯检查变得更加容易。要使用它,只需将该文件保存为〜/ .gdbinit 并正常运行gdb

即将发布的 GDB 8.3新功能

https:/ /sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/NEWS

  

终端样式现在可用于CLI和TUI。 GNU来源   突出显示还可用于提供源代码的样式   片段。请参阅“设置样式”以下命令,以获取更多信息。

你可以得到你想要的任何颜色;

# gdb
(gdb) shell echo -en '\E[47;34m'"\033[1m"
...
anything is now blue foreground and white background
...
(gdb) shell tput sgr0
... back to normal
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top