diff --git a/gdb/stack.c b/gdb/stack.c index c2323e1726d..a9f967113f6 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1154,7 +1154,8 @@ do_print_frame_info (struct ui_out *uiout, const frame_print_options &fp_opts, uiout->text ("\t"); } - print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); + if (opts.sourceprint) + print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); } /* If disassemble-next-line is set to on and there is line debug diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp index 841e603764c..ac0949cd084 100644 --- a/gdb/testsuite/gdb.base/options.exp +++ b/gdb/testsuite/gdb.base/options.exp @@ -182,6 +182,7 @@ proc_with_prefix test-print {{prefix ""}} { "-pretty" "-raw-values" "-repeats" + "-source" "-static-members" "-symbol" "-union" diff --git a/gdb/valprint.c b/gdb/valprint.c index db8affeb47a..4b178282050 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -114,6 +114,7 @@ struct value_print_options user_print_options = true, /* addressprint */ false, /* nibblesprint */ false, /* objectprint */ + true, /* sourceprint */ PRINT_MAX_DEFAULT, /* print_max */ PRINT_MAX_CHARS_DEFAULT, /* print_max_chars */ 10, /* repeat_count_threshold */ @@ -2873,6 +2874,16 @@ Printing of C++ virtual function tables is %s.\n"), value); } +/* Controls printing of source code. */ +static void +show_sourceprint (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("\ +Printing of source code to gdb console is %s.\n"), + value); +} + /* Controls looking up an object's derived type using what we find in its vtables. */ static void @@ -3083,6 +3094,14 @@ pretty-printers for that value.") N_("Show printing of C++ virtual function tables."), NULL, /* help_doc */ }, + boolean_option_def { + "source", + [] (value_print_options *opt) { return &opt->sourceprint; }, + show_sourceprint, /* show_cmd_cb */ + N_("Set printing of source code to gdb console."), + N_("Show printing of source code to gdb console."), + NULL, /* help_doc */ + }, }; /* See valprint.h. */ diff --git a/gdb/valprint.h b/gdb/valprint.h index 4f194b77008..c4672c03a9f 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -62,6 +62,9 @@ struct value_print_options in its vtables. */ bool objectprint; + /* Controls printing of source to console. */ + bool sourceprint; + /* Maximum number of elements to print for vector contents, or UINT_MAX for no limit. Note that "set print elements 0" stores UINT_MAX in print_max, which displays in a show command as "unlimited". */