如何在GDB中查看文件的完整路径?

时间:2011-02-01 01:32:04

标签: debugging gdb

当我停在gdb的断点时,它只显示filename.cpp。如何查看此文件的完整路径名?

3 个答案:

答案 0 :(得分:22)

使用info source命令获取当前堆栈帧的信息。

以下是其输出的示例:

(gdb) info source
Current source file is /build/gtk+2.0-LJ3oCC/gtk+2.0-2.24.30/modules/input/gtkimcontextxim.c
Located in /home/sashoalm/Desktop/compile/gtk+2.0-2.24.30/modules/input/gtkimcontextxim.c
Contains 1870 lines.
Source language is c.
Producer is GNU C11 5.3.1 20160225 -mtune=generic -march=i686 -g -g -O2 -O2 -fstack-protector-strong -fPIC -fstack-protector-strong.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.

答案 1 :(得分:1)

在Python脚本中

要学习Python脚本,或者只想查看完整路径而不是其他内容:

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk


class MCVEWindow(gtk.ApplicationWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._tree_view = gtk.TreeView()
        self._tree_view.set_hexpand(True)
        self._tree_view.set_vexpand(True)

        self.populate_tree_view()  # populate tree view with fake items

        window_column = gtk.TreeViewColumn(
            "Window", gtk.CellRendererText(),
            text=0
        )
        window_column.set_resizable(True)
        handle_column = gtk.TreeViewColumn(
            "Handle", gtk.CellRendererText(),
            text=1
        )
        class_column = gtk.TreeViewColumn(
            "Class name", gtk.CellRendererText(),
            text=2
        )
        self._tree_view.append_column(window_column)
        self._tree_view.append_column(handle_column)
        self._tree_view.append_column(class_column)

        scrolled_tree_view = gtk.ScrolledWindow()
        scrolled_tree_view.add(self._tree_view)

        toolbar = gtk.Toolbar()

        expand_tree_view_button = gtk.ToolButton(icon_name="list-add")
        expand_tree_view_button.connect(
            "clicked",
            lambda e: self._tree_view.expand_all()
        )
        collapse_tree_view_button = gtk.ToolButton(icon_name="list-remove")
        collapse_tree_view_button.connect(
            "clicked",
            lambda e: self._tree_view.collapse_all()
        )
        toolbar.insert(expand_tree_view_button, -1)
        toolbar.insert(collapse_tree_view_button, -1)

        status_bar = gtk.Statusbar()
        status_bar.push(
            status_bar.get_context_id("Status message"),
            "A status message."
        )

        self._master_grid = gtk.Grid()
        self._master_grid.attach(toolbar, 0, 0, 1, 1)
        self._master_grid.attach(scrolled_tree_view, 0, 1, 1, 1)
        self._master_grid.attach(status_bar, 0, 2, 1, 1)
        self.add(self._master_grid)

        self.connect("delete-event", gtk.main_quit)

        self.show_all()

    def populate_tree_view(self):
        tree_store = gtk.TreeStore(str, str, str)
        # Warnings don't occur when there are less than 100 "root" items
        for i in range(100):
            item1 = tree_store.append(
                None,
                ["Window " + str(i + 1), "12345678", "ClassName"]
            )
            for j in range(3):
                item2 = tree_store.append(
                    item1,
                    ["Window " + str(i + 1) + str(i + 2),
                     "12345678",
                     "ClassName"]
                )
                for k in range(5):
                    tree_store.append(
                        item2,
                        ["Window " + str(i + 1) + str(j + 1) + str(k + 1),
                         "12345678",
                         "ClassName"]
                    )

        self._tree_view.set_model(tree_store)


class MCVEApp(gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def do_activate(self):
        MCVEWindow()
        gtk.main()


if __name__ == "__main__":
    MCVEApp().run()

用法:

3.22.18

答案 2 :(得分:0)

Ciro Santill的优秀答案。但是,脚本需要进行一些小的修正才能使用我的gdb 8.0.1。

我还将其更改为将文本复制到剪贴板,以便我可以立即在vim中使用它。它与file_line.vim插件很好地配合使用。这是脚本生成的剪贴板内容的示例:

    System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "jpos_path");
    POSPrinterControl114 printer = (POSPrinterControl114) new POSPrinter();
    CashDrawerControl114 cashDrawer = (CashDrawerControl114) new CashDrawer();

    try {
        printer.open("POSPrinter");
        printer.claim(1000);
        printer.setDeviceEnabled(true);
        printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, "Test Print\n");


        cashDrawer.open("CashDrawer");
        cashDrawer.claim(1000);
        cashDrawer.setDeviceEnabled(true);

        cashDrawer.openDrawer();

    } catch (JposException e) {
        e.printStackTrace();
    }finally {
        try {
            cashDrawer.setDeviceEnabled(false);
            cashDrawer.release();
            cashDrawer.close();

            printer.setDeviceEnabled(false);
            printer.release();
            printer.close();

        } catch (JposException e) {
            e.printStackTrace();
        }

    }

脚本如下:

/home/ops1/projects/test01/main.cpp:5

以下是完成所有工作的步骤:

  1. 安装pyperclip python库 python3-pyperclip中的sudo zypper
  2. 将上面的脚本保存到文件中,比如file-path.py并将其复制到〜/ .gdb
  3. 使用添加以下行更新〜/ .gdbinit: source~ / .gdb / file-path.py
  4. 现在,您可以使用gdb
  5. 中的import pyperclip class Clippath (gdb.Command): """print absolute path""" def __init__(self): super(Clippath, self).__init__("clippath", gdb.COMMAND_USER) def invoke(self, arg, from_tty): symtabline = gdb.selected_frame().find_sal() pyperclip.copy(symtabline.symtab.fullname() + ":" + str(symtabline.line)) Clippath() 将路径和行复制到剪贴板

    阅读有关GDB Python API的更多信息 - link