public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: George Barrett <bob@bob131.so>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix handling of null stap semaphores
Date: Mon, 30 Dec 2019 17:59:00 -0000	[thread overview]
Message-ID: <825af859-3594-5e29-9921-822f4193750a@simark.ca> (raw)
In-Reply-To: <63-043i577lrr0nz3p9q-864io50kubhf/q6&oul1hzd/xh4.u6c@mail.bob131.so>

On 2019-12-30 10:38 a.m., George Barrett wrote:
> On Sun, Dec 29, 2019 at 01:58:46PM -0500, Simon Marchi wrote:
>> Though the ChangeLog should mention the modified functions, I propose to use
>> this:
>>
>> 	* stap-probe.c (stap_modify_semaphore): Don't check for null
>> 	semaphores.
>> 	(stap_probe::set_semaphore, stap_probe::clear_semaphore): Check
>> 	for null semaphores.
> 
> Ack.
> 
>> I'd really like if we could have a test for this, so that eventual refactors
>> don't re-introduce this bug.  Perhaps the gdb.base/stap-probe.exp test could
>> be enhanced to test that the ELF magic number hasn't been changed?
> 
> I was secretly hoping no-one would notice the absence of a test case ;)

Yeah, I know writing a test case is not the most fun part, but it pays in the
long run.  I can help if you are not familiar enough with tcl/expect/dejagnu.

>> One difficulty is finding out where it is, I don't know if there's a GDB
>> command that will compute that directly.  One way is to take the address of
>> a global variable before and after starting the process, and see how it has
>> been relocated, that would be the base of the image:
>>
>> (gdb) p &some_global
>> $1 = (int *) 0x402c <some_global>
>> (gdb) start
>> Temporary breakpoint 1 at 0x111d: file test.c, line 9.
>> Starting program: /home/simark/src/aoc/08/p2/a.out
>>
>> Temporary breakpoint 1, main () at test.c:9
>> 9	  for (i = 0; i < 1000; i++) {
>> (gdb) p &some_global
>> $2 = (int *) 0x55555555802c <some_global>
>> (gdb) p/x 0x55555555802c - 0x402c
>> $3 = 0x555555554000
>> (gdb) p (*(char*) 0x555555554000)@4
>> $4 = "\177ELF"
> 
> Is it too glibc-specific to use _r_debug? Something like the following:
> 
> (gdb) start
> Temporary breakpoint 1 at 0x4e60: file ../src/ls.c, line 1451.
> Starting program: /usr/bin/ls
> 
> Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd8d8) at ../src/ls.c:1451
> (gdb) p/x _r_debug.r_map->l_addr
> $1 = 0x555555554000
> (gdb) p (*(char*) _r_debug.r_map->l_addr)@4
> $2 = "\177ELF"

Hmm, it is not only glibc-specific (I believe?), but it also requires having glibc
debug symbols installed.  I just tried in an Alpine docker image (which uses musl),
and the address subtraction method works.  So between the two methods, I'd prefer
the address subtraction, since it works on more libc's, and it works without debug
info for the libc.

Simon

  reply	other threads:[~2019-12-30 17:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03 19:59 George Barrett
2019-12-18 17:20 ` [PING] " George Barrett
2019-12-28  5:28   ` [PING**2] " George Barrett
2019-12-29 18:58 ` Simon Marchi
2019-12-30 15:38   ` George Barrett
2019-12-30 17:59     ` Simon Marchi [this message]
2019-12-31  4:39       ` George Barrett
2019-12-31 17:37         ` Simon Marchi
2019-12-31 17:59           ` George Barrett
2019-12-31 17:56   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=825af859-3594-5e29-9921-822f4193750a@simark.ca \
    --to=simark@simark.ca \
    --cc=bob@bob131.so \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).