On 19 jan, 22:24, Konstantin Serebryany
<
konstantin.s.serebry...@gmail.com> wrote:
> I would expect that "clang -g -faddress-sanitizer" (w/o -O[123]) should
> produce a binary equally debuggable as "clang -g" would produce.
> We often use gdb on asan-built binarie, but most frequently we build with
> -O[12] and there are some problems with debugability.
>
> I've just tried a simplest possible experiment with clang (which I've just
> build from trunk) and I see a problem (even w/o asan):
>
> ----------------------------------------------------------------------------------
> % cat main.c
> int main(int argc, char *argv[]) {
> return argv[0][0];}
>
> % clang -g main.c && gdb a.out
> Reading symbols from /home/kcc/tmp/a.out...done.
> (gdb) b main
> Breakpoint 1 at 0x4004d0: file main.c, line 1.
> (gdb) r
> Starting program: /home/kcc/tmp/a.out
>
> Breakpoint 1, main (argc=0, argv=0x0) at main.c:1
> 1 int main(int argc, char *argv[]) {
> ----------------------------------------------------------------------------------
>
> The values of argc/argv are not seen by the debugger.
> This sounds like clang/llvm problem. Would you mind reporting it to
>
llvm...@cs.uiuc.edu?
> (Or I can do it too).
>
> Thanks for the report.
> --kcc
>
On my side I've made this test :
----------------------------------------------------------
› cat
test_debug.c
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int function2(char *text)
{
int ret = -1;
if (0 == strlen(text))
ret = 512;
else
ret = 8;
return ret;
}
static bool function1(int count, char *text)
{
bool status = true;
if (-1 == function2(text))
status = false;
printf("[%d] - '%s'\n", count, text);
return status;
}
int main(int argc, char const *argv[])
{
printf("start\n");
if (!function1(5, "test1"))
printf("error\n");
if (!function1(1, ""))
printf("error\n");
printf("end\n");
return 0;
}
----------------------------------------------------------
When I compile it using clang only, I get in gdb :
----------------------------------------------------------
› gdb ./a.out -batch -x
batch_gdb
$1 = "Inserting breakpoint... "
Breakpoint 1 at 0x40054c: file test_debug.c, line 8.
$2 = "Launching program... "
start
Breakpoint 1, function2 (text=0x400793 "test1") at test_debug.c:8
8 int ret = -1;
$3 = "Content of char *text in function2()... "
$4 = 0x400793 "test1"
$5 = "Going up into function1()... "
#1 0x000000000040065c in function1 (count=5, text=0x400793 "test1")
at test_debug.c:22
22 if (-1 == function2(text))
$6 = "[-] info locals in function1()... "
status = true
$7 = "[-] info args in function1()... "
count = 5
text = 0x400793 "test1"
[5] - 'test1'
[1] - ''
end
[Inferior 1 (process 4416) exited normally]
----------------------------------------------------------
but when compiling it with Address-Sanitizer I get :
----------------------------------------------------------
› gdb ./a.out -batch -x
batch_gdb
$1 = "Inserting breakpoint... "
Breakpoint 1 at 0x404f1b: file test_debug.c, line 8.
$2 = "Launching program... "
[Thread debugging using libthread_db enabled]
start
Breakpoint 1, function2 (text=0x7fffffffe2a0 "\340\363@") at
test_debug.c:8
8 int ret = -1;
$3 = "Content of char *text in function2()... "
$4 = 0x7fffffffe2a0 "\340\363@"
$5 = "Going up into function1()... "
#1 0x0000000000405522 in function1 (count=<optimized out>,
text=<optimized out>) at test_debug.c:22
22 if (-1 == function2(text))
$6 = "[-] info locals in function1()... "
status = 128
$7 = "[-] info args in function1()... "
count = <optimized out>
text = <optimized out>
[5] - 'test1'
[1] - ''
end
[Inferior 1 (process 10957) exited normally]
----------------------------------------------------------
› clang --
version
clang version 3.1 (trunk 148535)
Target: x86_64-unknown-linux-gnu
Thread model: posix
› cat batch_gdb
print "Inserting breakpoint... "
break function2
print "Launching program... "
run
print "Content of char *text in function2()... "
print text
print "Going up into function1()... "
up
print "[-] info locals in function1()... "
info locals
print "[-] info args in function1()... "
info args
delete 1
continue
quit
Should I post the problem on llvm-dev@ ,or enter a new bug in the
bugtracker ?
-- jonathan