This document lists some of the cases which lead to errors or improper results when debugging
with XLC and GCC compiled binaries. XLC generated binaries are the most affected once and lead 
to more failures than the GCC generated binaries. 

This document can be used as a quick guide to determine the cause and type of failure in case of
non-obivious conditions.

=> advance functionality is failing 

 16 void func()
 17 {
 18   x = x + 5;
 19   func2 ();
 20 }

(gdb) advance func()
func () at ./advance.c:1
19        func2 ();

 It breaks at line #19 instead at 18

=> setting break point is wrong in below example
  
 28 int main ()
 29 {
 30     extern void dummy();
 31 #ifdef usestubs
 32     set_debug_traps();
 33     breakpoint();
 34 #endif
 35     dummy();
 36     return 0;
 37 
 38 }

(gdb) break main
 Breakpoint 1 at 0x10000470: file ./gdb.base/all-types.c, line 36.
(gdb) run
 Starting program: /opt/freeware/src/packages/BUILD/gdb-7.3/gdb/testsuite/gdb.base/all-types
 Breakpoint 1, main () at ./gdb.base/all-types.c:36
 36          return 0;
 gdb) next
 38      } 

=> Printing union which is inside a structure may fail in below condition

  5 struct outer
  6 {
  7   int one;
  8   int two;
  9 
 10   struct
 11   {
 12     union {
 13       int three : 3;
 14       int four : 4;
 15     };
 16 
 17     union {
 18       int five : 3;
 19       int six : 4;
 20     };
 21   } data;
 22 };
 23 
 24 int main ()
 25 {
 26   struct outer val;
 27 
 28   memset (&val, 0, sizeof (val));
 29   val.data.six = 6;
 30 
 31   return 0;                     /* break here */
 32 }

(gdb) break main
Breakpoint 1 at 0x1000038c: file ./gdb.base/anon.c, line 28.
gdb) run
Starting program: /opt/freeware/src/packages/BUILD/gdb-7.3/gdb/testsuite/gdb.base/anon

Breakpoint 1, main () at ./gdb.base/anon.c:28
28        memset (&val, 0, sizeof (val));
(gdb) break 31
Breakpoint 2 at 0x100003ac: file ./gdb.base/anon.c, line 31.
(gdb) continue
Continuing.

Breakpoint 2, main () at ./gdb.base/anon.c:31
31        return 0;                     /* break here */
(gdb)print val.data.six
$1 = 0


=> List and function name fails

(gdb) list main
 No line number known for main.


=>Printing float values is wrong

(gdb) p t_float_values(3.14159,-2.3765)
$22 = 0

float float_val1 = 3.14159;
float float_val2 = -2.3765;
#define DELTA (0.001)


int t_float_values (float_arg1, float_arg2)
float float_arg1, float_arg2;
{
return ((float_arg1 - float_val1) < DELTA
           && (float_arg1 - float_val1) > -DELTA
          && (float_arg2 - float_val2) < DELTA
           && (float_arg2 - float_val2) > -DELTA);
 }


(gdb) p t_structs_a(struct_val1)
Too few arguments in function call.

 struct struct1 {
   char c;
   short s;
   int i;
   long l;
   float f;
   double d;
   char a[4];
 } struct_val1 = { 'x', 87, 76, 51, 2.1234, 9.876, "foo" };


=> breakpoint at main stops at line 94 instead of  93 in case of below code snippet

 80 int
 81 main (int argc, char **argv, char **envp)
 82 #else
 83 int
 84 main (argc, argv, envp)
 85 int argc;
 86 char *argv[], **envp;
 87 #endif
 88 {
 89 #ifdef usestubs
 90     set_debug_traps();  /* set breakpoint 5 here */
 91     breakpoint();
 92 #endif
 93     if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 he    re */
 94         fprintf (stderr, "usage:  factorial <number>\n");
 95         return 1;
 96     }
 97     printf ("%d\n", factorial (atoi ("6")));  /* set breakpoint 1 here */


=> Label breakpoint isn't working (same issue with gcc/xlc)

  int
  main (int argc, char *argv)
 {
   int i = 0;
   goto there;
 
  here:
    printf("not here\n");
    i = 1;
 
  there:
    printf("but here\n");
    if (i == 0)
     goto here;
  
  done:
   return 0;
  }

  (gdb) break here
 Function "here" not defined.
 Make breakpoint pending on future shared library load? (y or [n]) n
  (gdb) break main:there
 No source file named main.

=> printing struct and volatile enum variables may fail

struct some_struct
{
  int a;
  int b;
  unsigned char array[20];
} some_struct = {
  0x12345678,
  0x87654321,
  {
    0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
    0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
    0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
    0xaa, 0xaa, 0xaa, 0xaa, 0xaa
  }
};

(gdb) p/x some_struct
 No symbol "some_struct" in current context.


enum some_volatile_enum { enumvolval1, enumvolval2 };

/* A volatile enum variable whose name is the same as the enumeration
   name.  See PR11827.  */
volatile enum some_volatile_enum some_volatile_enum = enumvolval1;


 (gdb) print some_volatile_enum
 No symbol "some_volatile_enum" in current context.



=> printing struct value may fail

 struct link {
         struct link *next;
 #ifdef __STDC__
         struct link *(*linkfunc) (struct link *this, int flags);
 #else
         struct link *(*linkfunc) ();
 #endif
         struct t_struct stuff[1][2][3];
 } *s_link;


 (gdb) ptype struct link
 This context has class, union or enum link, not a struct.

=> Printing typedef enum may fail

 typedef enum {FALSE, TRUE} boolean;
 boolean v_boolean;

 (gdb) whatis v_boolean
 type = boolean

typedef int (*func_type) (int (*) (int, float), float);
 double (*old_fptr) ();
 double (*new_fptr) (void);
 int (*fptr) (int, float);
 int *(*fptr2) (int (*) (int, float), float);
 int (*xptr) (int (*) (), int (*) (void), int);
 int (*(*ffptr) (char)) (short);
 int (*(*(*fffptr) (char)) (short)) (long);

 (gdb) ptype func_type
 type = int (*)()

(gdb) ptype old_fptr
 No symbol "old_fptr" in current context.
 (gdb) ptype new_fptr
 No symbol "new_fptr" in current context.
 (gdb) ptype fptr
 No symbol "fptr" in current context.
 (gdb) ptype fptr2
 No symbol "fptr2" in current context.
 (gdb) ptype xptr
 No symbol "xptr" in current context.
 (gdb) ptype ffptr
 No symbol "ffptr" in current context.
 (gdb) ptype fffptr
 No symbol "fffptr" in current context.


=> find may fails to find correct memory pattern

static int8_t int8_search_buf[100];
#define CHUNK_SIZE 16000 /* same as findcmd.c's */
#define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
 42 static char *search_buf;
 43 static int search_buf_size;
 44 
 45 static int x;
 46 
 47 static void
 48 stop_here ()
 49 {
 50   x = 1; // stop here
 51 }
 52 
 53 static void
 54 init_bufs ()
 55 {
 56   search_buf_size = BUF_SIZE;
 57   search_buf = malloc (search_buf_size);
 58   if (search_buf == NULL)
 59     exit (1);
 60   memset (search_buf, 'x', search_buf_size);
 61 }
 62 
 63 int
 64 main ()
 65 {
 66   init_bufs ();
 67 
 68   stop_here ();
 69 
 70   /* Reference variables.  */
 71   x = int8_search_buf[0];
 72     return 0;
 73 }

 (gdb) break find.c:stop_here
 Breakpoint 1 at 0x1000042c: file ./find.c, line 51.
 gdb) run
 Starting program: /opt/freeware/src/packages/BUILD/gdb-7.3/gdb/testsuite/gdb.base/find 
 
 Breakpoint 1, stop_here () at ./find.c:51
 51      }
 (gdb) set *(int32_t*) &int8_search_buf[10] = 0x61616161
 (gdb) find &int8_search_buf[0], +sizeof(int8_search_buf), 'a', 'a', 'a'
 0x200008e6 <_$STATIC_BSS+22>
 0x200008e7 <_$STATIC_BSS+23>
 2 patterns found.
 (gdb) find &int8_search_buf[0], +10+3, "aaaa"
 Pattern not found.

=> list filename:function not resolving properly

list0.h
=====
  2 #ifdef PROTOTYPES
  3 extern void bar(int);
  4 static void foo (int x)
  5 #else
  6 static void foo (x) int x;
  7 #endif
  8 {
  9     bar (x++);
 10     bar (x++);
 11     bar (x++);
 12     bar (x++);
 13     bar (x++);

list0.c
====
  1 #include "list0.h"
  2 
  3 int main ()
  4 {
  5     int x;
  6 #ifdef usestubs
  7     set_debug_traps();
  8     breakpoint();
  9 #endif
 10     x = 0;
 11     foo (x++);
 12     foo (x++);
 13     foo (x++);
 14     foo (x++);
 15     foo (x++);
 16     foo (x++);


(gdb) list list0.c:foo
3       extern void bar(int);
4       static void foo (int x)
5       #else
6       static void foo (x) int x;
7       #endif
8       {
9           bar (x++);
10          bar (x++);
11          bar (x++);
12          bar (x++);



=> Can't print the static variables of the nondebugged images

 int dataglobal = 3;                     /* Should go in global data */
 static int datalocal = 4;               /* Should go in local data */
 int bssglobal;                          /* Should go in global bss */
 static int bsslocal; 

 (gdb) p datalocal
 No symbol table is loaded.  Use the "file" command.

 (gdb) p bsslocal
 No symbol table is loaded.  Use the "file" command.



=> Printing opaque pointer, struct pointer (statically) is wrong

#cat opaque0.c
struct foo *foop;
extern struct foo *getfoo ();
#ifdef PROTOTYPES
extern void putfoo (struct foo *foop);
#endif

int main ()
{
#ifdef usestubs
    set_debug_traps();
    breakpoint();
#endif
    foop = getfoo ();
    putfoo (foop);
    return 0;
}



# cat opaque1.c
struct foo {
    int a;
    int b;
} afoo = { 1, 2};

struct foo *getfoo ()
{
    return (&afoo);
}

#ifdef PROTOTYPES
void putfoo (struct foo *foop)
#else
void putfoo (foop)
     struct foo *foop;
#endif
{
}

After linking these two 

 (gdb) whatis foop
  type = <unknown type> *

=> printing memory attributes fail

 #define MEMSIZE 64
 tatic int mem1[MEMSIZE] = {111, 222, 333, 444, 555};
static int mem2[MEMSIZE];
 static int mem3[MEMSIZE];
 static int mem4[MEMSIZE];
static int mem5[MEMSIZE];

int main()
{
return 0;
 }

(gdb) info address mem1
Symbol "mem1" is static storage at address 0x200004b0.
 (gdb) info address mem2
 No symbol "mem2" in current context.
 (gdb) info address mem3
 No symbol "mem3" in current context.
 (gdb) info address mem4
 No symbol "mem4" in current context.
 (gdb) info address mem5
 No symbol "mem5" in current context.
 (gdb)  print &mem1[64]
 $1 = (int *) 0x200005b0
 (gdb) print &mem2[64]
 No symbol "mem2" in current context.
 (gdb)  print &mem3[64]
 No symbol "mem3" in current context.
 (gdb)  print &mem4[64]
 No symbol "mem4" in current context.
 (gdb)  print &mem5[64]
 No symbol "mem5" in current context.
 (gdb) mem -1 -1 ro
 invalid memory region: low >= high
 (gdb) mem -1 -1 rw
  invalid memory region: low >= high
  (gdb) info mem
  Using user-defined memory regions.
  Num Enb Low Addr   High Addr  Attrs 
 1   y   0x200004b0 0x200005b0 wo nocache 
 (gdb) print mem1[1]
 Cannot access memory at address 0x200004b4
 (gdb) print mem2[1] = 9
 No symbol "mem2" in current context.
 (gdb) print mem2[1]
 No symbol "mem2" in current context.

=>  test macro scoping fails

# cat macscp2.h
#define IN_MACSCP2_H

#undef WHERE
#define WHERE before macscp2_1
#define BEFORE_MACSCP2_1
#undef UNTIL_MACSCP2_1
void
macscp2_1 ()
{
  puts ("macscp2_1");
}

#include "macscp4.h"

#undef WHERE
#define WHERE before macscp2_2
#define BEFORE_MACSCP2_2
#undef UNTIL_MACSCP2_2
void
macscp2_2 ()
{
  puts ("macscp2_2");
}

#undef IN_MACSCP2_H


# cat macscp3.h
#define IN_MACSCP3_H

#undef WHERE
#define WHERE before macscp3_1
#define BEFORE_MACSCP3_1
#undef UNTIL_MACSCP3_1
void
macscp3_1 ()
{
  puts ("macscp3_1");
}

#include "macscp4.h"

#undef WHERE
#define WHERE before macscp3_2
#define BEFORE_MACSCP3_2
#undef UNTIL_MACSCP3_2
void
macscp3_2 ()
{
  puts ("macscp3_2");
}

#undef IN_MACSCP3_H


# cat macscp4.h
/* Put together a macro we can use as part of function names.  */
#undef MACSCP4_INCLUSION
#ifdef IN_MACSCP2_H
#define MACSCP4_INCLUSION from_macscp2
#endif
#ifdef IN_MACSCP3_H
#define MACSCP4_INCLUSION from_macscp3
#endif

#undef WHERE
#ifdef IN_MACSCP2_H
#define WHERE before macscp4_1_..., from macscp2.h
#define BEFORE_MACSCP4_1_FROM_MACSCP2
#undef UNTIL_MACSCP4_1_FROM_MACSCP2
#endif
#ifdef IN_MACSCP3_H
#define WHERE before macscp4_1_..., from macscp3.h
#define BEFORE_MACSCP4_1_FROM_MACSCP3
#undef UNTIL_MACSCP4_1_FROM_MACSCP3
#endif
void
SPLICE (macscp4_1_, MACSCP4_INCLUSION) ()
{
  puts ("macscp4_1_" STRINGIFY(MACSCP4_INCLUSION));
}

#undef WHERE
#ifdef IN_MACSCP2_H
#define WHERE before macscp4_2_..., from macscp2.h
#define BEFORE_MACSCP4_2_FROM_MACSCP2
#undef UNTIL_MACSCP4_2_FROM_MACSCP2
#endif
#ifdef IN_MACSCP3_H
#define WHERE before macscp4_2_..., from macscp3.h
#define BEFORE_MACSCP4_2_FROM_MACSCP3
#undef UNTIL_MACSCP4_2_FROM_MACSCP3
#endif
void
SPLICE (macscp4_2_, MACSCP4_INCLUSION) ()
{
  puts ("macscp4_2_" STRINGIFY(MACSCP4_INCLUSION));
}

#define DEFINED_IN_MACSCP4 this was defined in macscp4.h.


# cat macscp1.c
#include <stdio.h>

#define SPLICE(a, b) INNER_SPLICE(a, b)
#define INNER_SPLICE(a, b) a ## b
#define STRINGIFY(a) INNER_STRINGIFY(a)
#define INNER_STRINGIFY(a) #a

#define FIFTY_SEVEN 57

#define FORTY_EIGHT 48
#undef  FORTY_EIGHT

struct outer
{
  struct fields
  {
    struct fault
    {
      int addr;
    } fault;
  } fields;
};
struct outer address;

#define addr fields.fault.addr

/* A macro named UNTIL_<func> is #defined until just before the
   definition of the function <func>.

   A macro named BEFORE_<func> is not #defined until just before the
   definition of <func>.

   The macro WHERE is redefined before each function <func> to the
   token list ``before <func>''.

   The macscp IN_MACSCP2_H and IN_MACSCP3_H are defined while
   processing those header files; macscp4.h uses them to choose
   appropriate function names, output strings, and macro definitions.  */

#define UNTIL_MACSCP1_1
#define UNTIL_MACSCP2_1
#define UNTIL_MACSCP4_1_FROM_MACSCP2
#define UNTIL_MACSCP4_2_FROM_MACSCP2
#define UNTIL_MACSCP2_2
#define UNTIL_MACSCP1_2
#define UNTIL_MACSCP3_1
#define UNTIL_MACSCP4_1_FROM_MACSCP3
#define UNTIL_MACSCP4_2_FROM_MACSCP3
#define UNTIL_MACSCP3_2
#define UNTIL_MACSCP1_3

#define WHERE before macscp1_1
#define BEFORE_MACSCP1_1
#undef UNTIL_MACSCP1_1
void
macscp1_1 ()
{
  puts ("macscp1_1");
}

#include "macscp2.h"

#undef WHERE
#define WHERE before macscp1_2
#define BEFORE_MACSCP1_2
#undef UNTIL_MACSCP1_2
void
macscp1_2 ()
{
  puts ("macscp1_2");
}

#include "macscp3.h"

#undef WHERE
#define WHERE before macscp1_3
#define BEFORE_MACSCP1_3
#undef UNTIL_MACSCP1_3
void
macscp1_3 ()
{
  puts ("macscp1_3");
}

void
macscp_expr (void)
{
  int foo = -1;

  foo = 0;  /* set breakpoint here */
#define MACRO_TO_EXPAND foo
  foo = 1;
#undef MACRO_TO_EXPAND
  foo = 2;
}

#define TWENTY_THREE 23

int
main (int argc, char **argv)
{
  macscp1_1 ();
  macscp2_1 ();
  macscp4_1_from_macscp2 ();
  macscp4_2_from_macscp2 ();
  macscp2_2 ();
  macscp1_2 ();
  macscp3_1 ();
  macscp4_1_from_macscp3 ();
  macscp4_2_from_macscp3 ();
  macscp3_2 ();
  macscp1_3 ();
  macscp_expr ();
}


(gdb) list main
No line number known for main.
gdb) info macro WHERE
The symbol `WHERE' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
(gdb)list macscp2_2
No line number known for macscp2_2.
(gdb) info macro WHERE
The symbol `WHERE' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
(gdb)list macscp3_2
No line number known for macscp3_2.



Threads
=======

=> Thread scheduler locking not supported

(gdb)set scheduler-locking on
 Target 'aix-threads' cannot support this command.

=> call fails
 (gdb)call hand_call()
 gdbarch.c:1829: internal-error: gdbarch_pc_regnum: Assertion `gdbarch != NULL' failed.

=> aix-thread: store_registers: pthdb_pthread_setcontext returned NOTSUP

CORE debugging
==============
example code

# cat core.c
#include<stdio.h>
int *p = 0;
void b()
{
  *p = 1;
} 
void a()
{
    b();
}

int main()
{
    a();
}

32-bit(xlc)
-----------
Reading symbols from /home/sangam/gdb/test/core32_xlc...done.

warning: core file may not match specified executable file.
Program terminated with signal 11, Segmentation fault.
#0  0x10000394 in main () at core.c:5

warning: Source file is more recent than executable.
5         *p = 1;
(gdb) where
#0  0x10000394 in main () at core.c:5
(gdb) 

64-bit(xlc)
----------
Reading symbols from /home/sangam/gdb/test/core64_xlc...done.

warning: core file may not match specified executable file.
Core was generated by `core64_xlc'.
Program terminated with signal 11, Segmentation fault.
#0  0x000000010000044c in b () at core.c:5

warning: Source file is more recent than executable.
5         *p = 1;
(gdb) where
#0  0x000000010000044c in b () at core.c:5
#1  0x0000000100000490 in a () at core.c:9
#2  0x00000001000004d0 in main () at core.c:14

32-bit(gcc)
-----------
Reading symbols from /home/sangam/gdb/test/core32_gcc...done.

warning: core file may not match specified executable file.
Program terminated with signal 11, Segmentation fault.
#0  0x100003fc in main () at core.c:5

warning: Source file is more recent than executable.
5         *p = 1;
(gdb) where
#0  0x100003fc in main () at core.c:5

64-bit(xlc)
----------
Reading symbols from /home/sangam/gdb/test/core64_gcc...done.

warning: core file may not match specified executable file.
Core was generated by `core64_gcc'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000100000448 in ?? ()
(gdb) where
#0  0x0000000100000448 in ?? ()
#1  0x0000000100000484 in ?? ()
#2  0x0ffffffffffffb98 in ?? ()
#3  0x00000001000004c4 in ?? ()
#4  0x00000001000002dc in ?? ()
