This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 03/16] source, disasm: optionally prefix source lines with filename
- From: markus dot t dot metzger at intel dot com
- To: gdb-patches at sourceware dot org
- Cc: markus dot t dot metzger at gmail dot com, Markus Metzger <markus dot t dot metzger at intel dot com>
- Date: Thu, 10 May 2012 17:13:17 +0200
- Subject: [PATCH 03/16] source, disasm: optionally prefix source lines with filename
- References: <1336662810-21937-1-git-send-email-markus.t.metzger@intel.com>
From: Markus Metzger <markus.t.metzger@intel.com>
Add respective flags to print_source_lines () and gdb_disassembly () to prefix
the source line with its file name.
2012-05-10 Markus Metzger <markus.t.metzger@intel.com>
gdb/
* disasm.h (DISASSEMBLY_FILENAME): New macro
* disasm.c (do_mixed_source_and_assembly): Pass filename flag on to
print_source_lines ().
* symtab.h (PRINT_SOURCE_LINES_FILENAME): New print source lines flag
* source.c (print_source_lines_base): Prefix source line with filename if
PRINT_SOURCE_LINES_FILENAME flag is set.
---
gdb/disasm.c | 12 ++++++++----
gdb/disasm.h | 1 +
gdb/source.c | 5 +++++
gdb/symtab.h | 3 ++-
4 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 4902d95..d0a0be4 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -204,10 +204,14 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
int out_of_order = 0;
int next_line = 0;
int num_displayed = 0;
+ int psl_flags = 0;
struct cleanup *ui_out_chain;
struct cleanup *ui_out_tuple_chain = make_cleanup (null_cleanup, 0);
struct cleanup *ui_out_list_chain = make_cleanup (null_cleanup, 0);
+ if (flags & DISASSEMBLY_FILENAME)
+ psl_flags |= PRINT_SOURCE_LINES_FILENAME;
+
mle = (struct dis_line_entry *) alloca (nlines
* sizeof (struct dis_line_entry));
@@ -295,7 +299,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
ui_out_tuple_chain
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
- print_source_lines (symtab, next_line, mle[i].line + 1, 0);
+ print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
}
else
{
@@ -309,7 +313,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
print_source_lines (symtab, next_line, next_line + 1,
- 0);
+ psl_flags);
ui_out_list_chain_line
= make_cleanup_ui_out_list_begin_end (uiout,
"line_asm_insn");
@@ -321,7 +325,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
ui_out_tuple_chain
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
- print_source_lines (symtab, next_line, mle[i].line + 1, 0);
+ print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
}
}
else
@@ -329,7 +333,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
ui_out_tuple_chain
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
- print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0);
+ print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flags);
}
next_line = mle[i].line + 1;
diff --git a/gdb/disasm.h b/gdb/disasm.h
index 5b459f4..5ae71c9 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -23,6 +23,7 @@
#define DISASSEMBLY_RAW_INSN (0x1 << 1)
#define DISASSEMBLY_OMIT_FNAME (0x1 << 2)
#define DISASSEMBLY_PRECISE_INSN (0x1 << 3)
+#define DISASSEMBLY_FILENAME (0x1 << 4)
struct ui_out;
struct ui_file;
diff --git a/gdb/source.c b/gdb/source.c
index 4dd7ed2..a1ca6d3 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1315,6 +1315,11 @@ print_source_lines_base (struct symtab *s, int line, int stopline, int flags)
if (c == EOF)
break;
last_line_listed = current_source_line;
+ if (flags & PRINT_SOURCE_LINES_FILENAME)
+ {
+ ui_out_text (uiout, s->filename);
+ ui_out_text (uiout, ":");
+ }
sprintf (buf, "%d\t", current_source_line++);
ui_out_text (uiout, buf);
do
diff --git a/gdb/symtab.h b/gdb/symtab.h
index b252725..62a6a7b 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1128,7 +1128,8 @@ extern int identify_source_line (struct symtab *, int, int, CORE_ADDR);
/* Flags passed as 4th argument to print_source_lines. */
enum print_source_lines_flags {
- PRINT_SOURCE_LINES_NOERROR = (0x1 << 0)
+ PRINT_SOURCE_LINES_NOERROR = (0x1 << 0),
+ PRINT_SOURCE_LINES_FILENAME = (0x1 << 1)
};
extern void print_source_lines (struct symtab *, int, int, int);
--
1.7.1