From owner-freebsd-bugs@freebsd.org Thu Nov 7 05:56:06 2019 Return-Path: Delivered-To: freebsd-bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 02A201A81E7 for ; Thu, 7 Nov 2019 05:56:06 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 477t1d6K5kz48G4 for ; Thu, 7 Nov 2019 05:56:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id D6B171A81E6; Thu, 7 Nov 2019 05:56:05 +0000 (UTC) Delivered-To: bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D52EA1A81E5 for ; Thu, 7 Nov 2019 05:56:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 477t1d55tXz48G3 for ; Thu, 7 Nov 2019 05:56:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8EE4292EA for ; Thu, 7 Nov 2019 05:56:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id xA75u5FL083889 for ; Thu, 7 Nov 2019 05:56:05 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id xA75u5Rf083888 for bugs@FreeBSD.org; Thu, 7 Nov 2019 05:56:05 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 241773] lldb does not display external variables properly. Date: Thu, 07 Nov 2019 05:56:05 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 12.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: bc979@lafn.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Nov 2019 05:56:06 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D241773 Bug ID: 241773 Summary: lldb does not display external variables properly. Product: Base System Version: 12.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: bc979@lafn.org Here is an issue that has plagued me for some time: Using FreeBSD 12.0: testlib.c: #include #include #include #include char id[4]; int sock; void testfunc() { struct stat sb; stat("testlib.c", &sb); strcpy (id, "aa"); sock =3D 5; printf("Size of testlib.c is %i bytes.\n", (int)sb.st_size); } testprog.c: #include extern char id[4]; extern int sock; void testfunc(void); int main(int argc, char **argv) { testfunc(); printf ("id =3D %s\n", id); printf ("sock =3D %d\n", sock); return 0; } Makefile: all: clean testprog run testprog: cc -Wall -g -c -fPIC -o testlib.o testlib.c cc -shared -Wl,-export-dynamic -o testlib.so testlib.o cc -Wall -g -o testprog ./testlib.so testprog.c clean: rm -f testlib.o testlib.so testprog run: ./testprog Using make: rm -f testlib.o testlib.so testprog cc -Wall -g -c -fPIC -o testlib.o testlib.c cc -shared -Wl,-export-dynamic -o testlib.so testlib.o cc -Wall -g -o testprog ./testlib.so testprog.c ./testprog Size of testlib.c is 268 bytes. id =3D aa sock =3D 5 Running lldb: master# lldb testprog (lldb) target create "testprog" Current executable set to 'testprog' (x86_64). (lldb) b main Breakpoint 1: where =3D testprog`main + 22 at testprog.c:8, address =3D 0x0000000000201366 (lldb) r Process 34787 launching Process 34787 launched: '/home/doug/zzz/testprog' (x86_64) Process 34787 stopped * thread #1, name =3D 'testprog', stop reason =3D breakpoint 1.1 frame #0: 0x0000000000201366 testprog`main(argc=3D1, argv=3D0x00007fffff= ffeb38) at testprog.c:8 5=20=20=20=20=20 6 void testfunc(void); 7 int main(int argc, char **argv) { -> 8 testfunc(); 9 printf ("id =3D %s\n", id); 10 printf ("sock =3D %d\n", sock); 11 return 0; (lldb) n Size of testlib.c is 268 bytes. Process 34787 stopped * thread #1, name =3D 'testprog', stop reason =3D step over frame #0: 0x000000000020137f testprog`main(argc=3D1, argv=3D0x00007fffff= ffeb38) at testprog.c:9 6 void testfunc(void); 7 int main(int argc, char **argv) { 8 testfunc(); -> 9 printf ("id =3D %s\n", id); 10 printf ("sock =3D %d\n", sock); 11 return 0; 12 } (lldb) p id error: use of undeclared identifier 'id' (lldb) p sock error: Couldn't materialize: couldn't get the value of variable sock: testlib.so[0x4004] can't be resolved, testlib.so is not currently loaded error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression (lldb) c id =3D aa sock =3D 5 Process 34787 resuming You notice that lldb cannot display values for id or sock. It even gives q= uite different messages about them. However the program can access the values a= nd it prints them out properly. Why can't lldb see them? How can that be corrected? What is even more interesting is that in the real application there are qui= te a few of these global variables and lldb can display some of them, just not a= ll.=20 Possibly it has to do with the specific names as DATE generally works. sock and id never seem to work. Now using FreeBSD 12.1: We now have 12.1 with an updated compiler and linker. Things have changed.= I added a bit to testprog.c: master# more testprog.c #include extern char id[4]; extern int sock; int unknown; void testfunc(void); int main(int argc, char **argv) { testfunc(); unknown =3D 9; printf ("id (%x) =3D %s\n", (int)&id, id); printf ("sock(%x) =3D %d\n", (int)&sock, sock); printf ("unknown (%x) =3D %d\n", (int)&unknown, unknown); return 0; } running it yields: master# ./testprog Size of testlib.c is 268 bytes. id (20400c) =3D aa sock(204010) =3D 5 unknown (204008) =3D 9 That appears to be correct. Everything worked. However, with lldb, instea= d of error messages I get wrong values: master# lldb testprog (lldb) target create "testprog" Current executable set to 'testprog' (x86_64). (lldb) b main Breakpoint 1: where =3D testprog`main + 22 at testprog.c:9:3, address =3D 0x00000000002012f6 (lldb) r Process 6039 launching Process 6039 launched: '/home/doug/zzz/testprog' (x86_64) Process 6039 stopped * thread #1, name =3D 'testprog', stop reason =3D breakpoint 1.1 frame #0: 0x00000000002012f6 testprog`main(argc=3D1, argv=3D0x00007fffff= ffeb38) at testprog.c:9:3 6=20=20=20=20=20 7 void testfunc(void); 8 int main(int argc, char **argv) { -> 9 testfunc(); 10 unknown =3D 9; 11 printf ("id (%x) =3D %s\n", (int)&id, id); 12 printf ("sock(%x) =3D %d\n", (int)&sock, sock); (lldb) n Size of testlib.c is 268 bytes. Process 6039 stopped * thread #1, name =3D 'testprog', stop reason =3D step over frame #0: 0x0000000000201307 testprog`main(argc=3D1, argv=3D0x00007fffff= ffeb38) at testprog.c:10:11 7 void testfunc(void); 8 int main(int argc, char **argv) { 9 testfunc(); -> 10 unknown =3D 9; 11 printf ("id (%x) =3D %s\n", (int)&id, id); 12 printf ("sock(%x) =3D %d\n", (int)&sock, sock); 13 printf ("unknown (%x) =3D %d\n", (int)&unknown, unknown); (lldb)=20 Process 6039 stopped * thread #1, name =3D 'testprog', stop reason =3D step over frame #0: 0x0000000000201312 testprog`main(argc=3D1, argv=3D0x00007fffff= ffeb38) at testprog.c:11:3 8 int main(int argc, char **argv) { 9 testfunc(); 10 unknown =3D 9; -> 11 printf ("id (%x) =3D %s\n", (int)&id, id); 12 printf ("sock(%x) =3D %d\n", (int)&sock, sock); 13 printf ("unknown (%x) =3D %d\n", (int)&unknown, unknown); 14 return 0; (lldb) p id (char [4]) $0 =3D "" (lldb) p &id (char (*)[4]) $1 =3D 0x000000080024d000 (lldb) p unknown (int) $2 =3D 9 (lldb) p &unknown (int *) $3 =3D 0x0000000000204008 (lldb)=20 For the variable unknown lldb displays the correct address and value. For = id and sock, it displays the wrong address and the value at the wrong address.= =20 The correct values are in the proper addresses: x 0x204008 0x00204008: 09 00 00 00 61 61 00 00 05 00 00 00 00 00 00 00 ....aa........= .. --=20 You are receiving this mail because: You are the assignee for the bug.=