gdb list not from the first line

Bug #1390905 reported by herozem
4
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gdb (Ubuntu)
Invalid
Low
Unassigned

Bug Description

when I use gdb list command, it does not list source code from the first line.

Revision history for this message
Matthias Klose (doko) wrote :

test case is missing. this usually works me.

Changed in gdb (Ubuntu):
status: New → Incomplete
importance: Undecided → Low
Revision history for this message
herozem (herozem-deactivatedaccount) wrote :

here is a test case:

```c
#include <stdio.h>

int maxsubsum(const int a[], int left, int right)
{
  int maxleftsum, maxrightsum;
  int maxleftbordersum, maxrightbordersum;
  int leftbordersum, rightbordersum;
  int center, i;

  if (left == right) {
    // base case
    if (a[left] > 0) {
      return a[left];
    } else {
      return (0);
    }
  }

  center = (left + right)/2;
  maxleftsum = maxsubsum(a, left, center);
  maxrightsum = maxsubsum(a, center, right);

  maxleftbordersum = 0;
  leftbordersum = 0;
  for (i = center; i >= left; i--) {
    leftbordersum += a[i];
    if( leftbordersum > maxleftbordersum ) {
      maxleftbordersum = leftbordersum;
    }
  }

  maxrightbordersum = 0;
  rightbordersum = 0;
  for (i = center+i; i <= right; i++) {
    rightbordersum += a[i];
    if (rightbordersum > maxrightbordersum) {
      maxrightbordersum = rightbordersum;
    }
  }

  return max_in3(maxleftsum, maxrightsum, maxleftbordersum+maxrightbordersum);
}

int max_subsequence_sum(const int a[], int n)
{
  return maxsubsum(a, 0, n-1);
}

int max_in3(int a, int b, int c)
{
  a = a > b? a: b;
  a = a > c? a: c;
  return a;
}

int main(void)
{
  int nums[] = { 1, 2, 3, -7, 8 };
  max_subsequence_sum(nums, 5);
  return 0;
}
```

first, compile it with -g option: `gcc -g max_sub.c`, and then debug `gdb ./a.out`

when I type list command in gdb, it will display:

```shell
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) list
49 int max_in3(int a, int b, int c)
50 {
51 a = a > b? a: b;
52 a = a > c? a: c;
53 return a;
54 }
55
56 int main(void)
57 {
58 int nums[] = { 1, 2, 3, -7, 8 };
(gdb)

```

it's not list from the 1st line.

Matthias Klose (doko)
Changed in gdb (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Dominik Viererbe (dviererbe) wrote :

Thanks for reporting this bug to help improve Ubuntu!

I looked into the source code for the gdb list command (see at the end of this comment). It looks to me that gdb will center the listing if it is called for the first time with no other parameters.

If you want that the listing starts at the beginning of the file, use "list 1" or "list FILE:1". (See more help by typing "help list").

We appreciate that this bug may be old and you might not be interested in discussing it anymore. But if you are then please re-test. If you then still think that this is a bug, please add a comment here telling us, why you think this is a bug, how to re-produce it and which version it is in (or at least which version you used).

Partial Source Code of gdb list command
=======================================
/* Pull in the current default source line if necessary. */
  if (arg == NULL || ((arg[0] == '+' || arg[0] == '-') && arg[1] == '\0'))
    {
      set_default_source_symtab_and_line ();
      symtab_and_line cursal = get_current_source_symtab_and_line ();

      /* If this is the first "list" since we've set the current
  source line, center the listing around that line. */
      if (get_first_line_listed () == 0)
 {
   int first;

   first = std::max (cursal.line - get_lines_to_list () / 2, 1);

   /* A small special case --- if listing backwards, and we
      should list only one line, list the preceding line,
      instead of the exact line we've just shown after e.g.,
      stopping for a breakpoint. */
   if (arg != NULL && arg[0] == '-'
       && get_lines_to_list () == 1 && first > 1)
     first -= 1;

   print_source_lines (cursal.symtab, source_lines_range (first), 0);
 }

Changed in gdb (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.