From owner-freebsd-questions@freebsd.org Wed Oct 16 23:09:48 2019 Return-Path: Delivered-To: freebsd-questions@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 831F7152625 for ; Wed, 16 Oct 2019 23:09:48 +0000 (UTC) (envelope-from mafsys1234@gmail.com) Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46tp0W1xsSz4PKr for ; Wed, 16 Oct 2019 23:09:47 +0000 (UTC) (envelope-from mafsys1234@gmail.com) Received: by mail-pf1-x429.google.com with SMTP id v4so335410pff.6 for ; Wed, 16 Oct 2019 16:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=f47d4qQN5MjmmtsxIB1sQHNa7u099KbEnuPi3MLcPQ4=; b=k44zuxqzzUWoaE7EGU1CE6D4U81DStOJMzfbbOYuU7fUdNyDrzaI2fZJLllY5qVI6F mxxr2Q+nYskLiyjVUFlSAYwk84d+RC5y8GjsXOGH8+jIg0CIAdMmkg72DimrP1tZlym9 4OduQXnm7xetzZHLxt+4ynw1xdM+Xs11UwxyZZDHuYrSxnkFn4M0LROcwSxbzJDdBwb8 oKBYtfo5azaiGJXGW/uJbZss7E8CfQoTuOl+l+DIJm57fGNvpR4jVG9N6KrheF0qRIvd EQdkyzJ4bQ5X18Nc382n8iIcIC5uBO2I1WmaKRCuf36HpPNQAXjwIC2eq/gqIU56+woG dItg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=f47d4qQN5MjmmtsxIB1sQHNa7u099KbEnuPi3MLcPQ4=; b=NPHH5KLZNSbM5zFYr+J6TVSWwagnHkfzj/7okDgXjvB95nbXhRdhAm0Hx5+P6qiRnj ko9tAV4Bo3u48th486zy1lS5YEFGHselwtROAPQuuxzLVUgftvQx7fKMLCbCflo2qnyc oGTePGH2VbGKef8wEsso2KmddT0xjmwQA66VmEmq24m8rAxdxqfI3Qv9qL9Lfe+PK4mR Vx17qlv+zO5j02Ja2FsfyaOF6eblOhK2O9mCf6h8OLCBZWybnxtt+YDY9rLQAuMD8tb/ nrZ1F48D7tOkf/VbEIpXp+qPGTHM2nwfm3WYGs5J5Xwr/n9oNreriGvGpGDBJzvyRTJP +Rjg== X-Gm-Message-State: APjAAAVYDVDIbY4OF4fpw+7rXAoFCsk2DKUN6a94oERQl8o6JJRswdGu z6xO+ZOqX8luhNSjbzFete44eboC X-Google-Smtp-Source: APXvYqwiFq+Z4A4bUVDtKN0i/izOLh90+roZV6gof6g3JSSUchtAUd1uN5mMDlB32ESqv4Na31psHQ== X-Received: by 2002:a63:d1:: with SMTP id 200mr694115pga.108.1571267383918; Wed, 16 Oct 2019 16:09:43 -0700 (PDT) Received: from [192.168.1.10] (C-59-101-161-221.mel.connect.net.au. [59.101.161.221]) by smtp.gmail.com with ESMTPSA id b16sm166260pfb.54.2019.10.16.16.09.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Oct 2019 16:09:43 -0700 (PDT) Subject: Re: Extension to previous posts: Problems with ld, libc, and "struct stat" To: Doug Hardie , FreeBSD Questions References: From: MJ Message-ID: Date: Thu, 17 Oct 2019 10:09:18 +1100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: 46tp0W1xsSz4PKr X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=k44zuxqz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of mafsys1234@gmail.com designates 2607:f8b0:4864:20::429 as permitted sender) smtp.mailfrom=mafsys1234@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RECEIVED_SPAMHAUS_PBL(0.00)[221.161.101.59.khpj7ygk5idzvmvt5x4ziurxhy.zen.dq.spamhaus.net : 127.0.0.10]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; IP_SCORE_FREEMAIL(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[9.2.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; IP_SCORE(0.00)[ip: (-8.38), ipnet: 2607:f8b0::/32(-2.47), asn: 15169(-2.10), country: US(-0.05)]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2019 23:09:48 -0000 On 17/10/2019 8:02 am, Doug Hardie wrote: > Here is an issue that has plagued me for some time: > > testlib.c: > #include > #include > #include > #include > > char id[4]; > int sock; > > void testfunc() { > struct stat sb; > stat("testlib.c", &sb); > strcpy (id, "aa"); > sock = 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 = %s\n", id); > printf ("sock = %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 = aa > sock = 5 > > > Running lldb: > master# lldb testprog > (lldb) target create "testprog" > Current executable set to 'testprog' (x86_64). > (lldb) b main > Breakpoint 1: where = testprog`main + 22 at testprog.c:8, address = 0x0000000000201366 > (lldb) r > Process 34787 launching > Process 34787 launched: '/home/doug/zzz/testprog' (x86_64) > Process 34787 stopped > * thread #1, name = 'testprog', stop reason = breakpoint 1.1 > frame #0: 0x0000000000201366 testprog`main(argc=1, argv=0x00007fffffffeb38) at testprog.c:8 > 5 > 6 void testfunc(void); > 7 int main(int argc, char **argv) { > -> 8 testfunc(); > 9 printf ("id = %s\n", id); > 10 printf ("sock = %d\n", sock); > 11 return 0; > (lldb) n > Size of testlib.c is 268 bytes. > Process 34787 stopped > * thread #1, name = 'testprog', stop reason = step over > frame #0: 0x000000000020137f testprog`main(argc=1, argv=0x00007fffffffeb38) at testprog.c:9 > 6 void testfunc(void); > 7 int main(int argc, char **argv) { > 8 testfunc(); > -> 9 printf ("id = %s\n", id); > 10 printf ("sock = %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 = aa > sock = 5 > Process 34787 resuming > > > You notice that lldb cannot display values for id or sock. It even gives quite different messages about them. However the program can access the values and 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 quite a few of these global variables and lldb can display some of them, just not all. Possibly it has to do with the specific names as DATE generally works. sock and id never seem to work. > > -- Doug Well it's obviously wrong. It's a bug in lldb. Unless you have to specifically load the shared library in? (process load testlib?) I tested this with gdb, it works as expected. That's probably why I still use gdb... > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" >