aboutsummaryrefslogtreecommitdiff
path: root/gdb/source.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/source.c')
-rw-r--r--gdb/source.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/gdb/source.c b/gdb/source.c
index 13cb8d6..1018d2c 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -354,11 +354,11 @@ select_source_symtab ()
struct symtab *new_symtab = nullptr;
- for (objfile *ofp : current_program_space->objfiles ())
+ for (objfile &ofp : current_program_space->objfiles ())
{
- for (compunit_symtab *cu : ofp->compunits ())
+ for (compunit_symtab &cu : ofp.compunits ())
{
- for (symtab *symtab : cu->filetabs ())
+ for (symtab *symtab : cu.filetabs ())
{
const char *name = symtab->filename;
int len = strlen (name);
@@ -374,9 +374,9 @@ select_source_symtab ()
if (new_symtab != nullptr)
return;
- for (objfile *objfile : current_program_space->objfiles ())
+ for (objfile &objfile : current_program_space->objfiles ())
{
- symtab *s = objfile->find_last_source_symtab ();
+ symtab *s = objfile.find_last_source_symtab ();
if (s)
new_symtab = s;
}
@@ -437,8 +437,8 @@ void
forget_cached_source_info (void)
{
for (struct program_space *pspace : program_spaces)
- for (objfile *objfile : pspace->objfiles ())
- objfile->forget_cached_source_info ();
+ for (objfile &objfile : pspace->objfiles ())
+ objfile.forget_cached_source_info ();
g_source_cache.clear ();
last_source_visited = NULL;
@@ -774,9 +774,9 @@ prepare_path_for_appending (const char *path)
If FILENAME_OPENED is non-null, set it to a newly allocated string naming
the actual file opened (this string will always start with a "/"). We
- have to take special pains to avoid doubling the "/" between the directory
- and the file, sigh! Emacs gets confuzzed by this when we print the
- source file name!!!
+ have to ensure that we avoid doubling the "/" between the directory and the
+ file, because Emacs has special treatment of double slashes.
+ See "(emacs) Minibuffer File".
If OPTS has OPF_RETURN_REALPATH set return FILENAME_OPENED resolved by
gdb_realpath. Even without OPF_RETURN_REALPATH this function still returns
@@ -1312,14 +1312,12 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
int nlines = stopline - line;
struct ui_out *uiout = current_uiout;
- /* Regardless of whether we can open the file, set current_source_symtab. */
+ /* Regardless of whether we can open the file, we'll want to set
+ current_source_symtab, but not if throw an error, or return without
+ printing any source lines. */
current_source_location *loc
= get_source_location (current_program_space);
- loc->set (s, line);
- first_line_listed = line;
- last_line_listed = line;
-
/* If printing of source lines is disabled, just print file and line
number. */
if (uiout->test_flags (ui_source_list) && source_open)
@@ -1380,6 +1378,10 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
uiout->text ("\n");
}
+ loc->set (s, line);
+ first_line_listed = line;
+ last_line_listed = line;
+
return;
}
@@ -1399,12 +1401,9 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
}
const char *iter = lines.c_str ();
- int new_lineno = loc->line ();
- while (nlines-- > 0 && *iter != '\0')
+ int new_lineno = line;
+ for (; nlines-- > 0 && *iter != '\0'; ++new_lineno)
{
- char buf[20];
-
- last_line_listed = loc->line ();
if (flags & PRINT_SOURCE_LINES_FILENAME)
{
uiout->message ("%ps",
@@ -1415,7 +1414,6 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
uiout->message ("%ps\t", styled_string (line_number_style.style (),
pulongest (new_lineno)));
- ++new_lineno;
while (*iter != '\0')
{
@@ -1457,6 +1455,8 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
}
else if (*iter > 0 && *iter < 040)
{
+ char buf[20];
+
xsnprintf (buf, sizeof (buf), "^%c", *iter + 0100);
uiout->text (buf);
++iter;
@@ -1470,7 +1470,11 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
uiout->text ("\n");
}
- loc->set (loc->symtab (), new_lineno);
+ /* As NEW_LINENO was incremented after displaying the last source line,
+ the last line shown was the one before NEW_LINENO. */
+ first_line_listed = line;
+ last_line_listed = new_lineno - 1;
+ loc->set (s, new_lineno);
}
@@ -1910,9 +1914,7 @@ source_lines_range::source_lines_range (int startline,
}
-void _initialize_source ();
-void
-_initialize_source ()
+INIT_GDB_FILE (source)
{
init_source_path ();