py
class GrepCmd (gdb.Command):
"""Execute command, but only show lines matching the pattern
Usage: grep_cmd <cmd> <pattern> """
def __init__ (_):
super ().__init__ ("grep_cmd", gdb.COMMAND_STATUS)
def invoke (_, args_raw, __):
args = gdb.string_to_argv(args_raw)
if len(args) != 2:
print("Wrong parameters number. Usage: grep_cmd <cmd> <pattern>")
else:
for line in gdb.execute(args[0], to_string=True).splitlines():
if args[1] in line:
print(line)
GrepCmd() # required to get it registered
end
4条答案
按热度按时间ibps3vxo1#
您可以使用
pipe
命令ne5o7dgx2#
(gdb)打印 * 此|格雷普
实现这一点的"标准"方法是在
emacs
中使用Meta-X gdb
。另一种选择:
与上面的补丁相比,cnicutar提到的补丁看起来确实很吸引人,我猜它(或它的等价物)从未提交的原因是大多数GDB维护者使用
emacs
,所以一开始就没有这个问题。fhity93d3#
最简单的方法是利用gdb python。
假设你已经启用了命令历史记录,你可以只输入一次,然后按Ctrl+ Rb.exec把它从历史记录中拉出来。接下来只需根据你的要求修改
attribute
和*this
。您也可以将其简化为:
为此,只需将以下内容添加到您的
.gdbinit
文件:uplii1fm4#
我知道这是一个老职位,但因为我发现它看起来做同样的事情,我想我会添加到Hi-Angel的答案说,你可以突出显示搜索词,在python输出,在红色的一个取代打印行与下面:
这只是使用
ascii escape
命令的颜色,所以应该工作在Linux和Windows终端,你可以很容易地改变颜色。