Posting here rather than gcc.help since I consider this behaviour to be
a bug.
Here is my demo program to illustrate the buggy behavior:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define PATH_SEP '/'
static unsigned char *replace_HOME(
unsigned char *filespec)
{
unsigned char tmpspec[300],
*tstr,
*HOME_env = (unsigned char *)getenv("HOME");
size_t sl;
if ( *filespec == '~' && HOME_env ) {
tstr = &filespec[1];
memset(tmpspec,0,300);
strcpy((char *)tmpspec,(char *)HOME_env);
sl = strlen((char *)tmpspec);
if ( (tmpspec[sl - 1] != PATH_SEP) && (*tstr != PATH_SEP) ) {
tmpspec[sl++] = PATH_SEP;
} else if ( (tmpspec[sl - 1] == PATH_SEP) && (tstr[1] ==
PATH_SEP) ) {
tstr++;
} // endif
strcat((char *)tmpspec,(char *)tstr);
filespec = (unsigned char *)strdup((char *)tmpspec);
} // endif
return filespec;
} // replace_HOME
/* Main Program
*/
int main(
unsigned argc,
unsigned char **argv,
unsigned char **envp)
{
unsigned char *filespc = "~/tmp/dumpfile";
printf("Returned filespc: %s\n",replace_HOME(filespc));
} // end main
When I step through the function "replace_HOME" (which replaces '~' with
the value of the HOME environment variable), kdbg only displays the
'tmpspec' local variable until I execute the line:
memset(tmpspec,0,300);
After executing this line, kdbg displays all of the local variables. I
have noticed previously that kdbg omits some local variables in the
'locals' window. That behaviour may (is probably?) related to this
behaviour also.
Now I do not think this should be normal behaviour, but hesitate to
report it as a bug.
The demo program above was compiled using the following command line:
gcc -v -save-temps -g -std=gnu99 -Wunused-variable testfile.c -o
testfile 2> savetemps
The savetemps output file is:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc
--disable-werror --with-arch-32=i686 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-std=gnu99'
'-Wunused-variable' '-o' 'testfile' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/cc1 -E -quiet -v -imultilib .
-imultiarch x86_64-linux-gnu testfile.c -mtune=generic -march=x86-64
-std=gnu99 -Wunused-variable -g -fworking-directory -fpch-preprocess
-fstack-protector -o testfile.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.6/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-std=gnu99'
'-Wunused-variable' '-o' 'testfile' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/cc1 -fpreprocessed testfile.i -quiet
-dumpbase testfile.c -mtune=generic -march=x86-64 -auxbase testfile -g
-Wunused-variable -std=gnu99 -version -fstack-protector -o testfile.s
GNU C (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version
3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version
3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 75e879ed14f91af504f4150eadeaa0e6
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-std=gnu99'
'-Wunused-variable' '-o' 'testfile' '-mtune=generic' '-march=x86-64'
as --64 -o testfile.o testfile.s
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-std=gnu99'
'-Wunused-variable' '-o' 'testfile' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --sysroot=/ --build-id
--no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64
--hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o
testfile
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o
-L/usr/lib/gcc/x86_64-linux-gnu/4.6
-L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib
-L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu
-L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../..
testfile.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
I'm running Kubuntu 12.04.
gcc -v displays:
$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc
--disable-werror --with-arch-32=i686 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Has this behaviour been noted before and corrected in more recent
versions of kdbg?
Thanks,
Terry (geezers)