From: Simon Marchi <simark@simark.ca>
To: "Frank Ch. Eigler" <fche@redhat.com>
Cc: Aaron Merey <amerey@redhat.com>, Tom Tromey <tom@tromey.com>,
Christian Biesinger via gdb-patches <gdb-patches@sourceware.org>,
Christian Biesinger <cbiesinger@google.com>
Subject: Re: [RFC PATCH] Support debuginfo and source file fetching via debuginfo server
Date: Tue, 05 Nov 2019 15:19:00 -0000 [thread overview]
Message-ID: <e05b912e-5a5e-afb7-1182-016e03ef15d1@simark.ca> (raw)
In-Reply-To: <20191105102519.GA18724@redhat.com>
On 2019-11-05 5:25 a.m., Frank Ch. Eigler wrote:
> Hi -
>
>> Maybe a user_data void pointer would be useful, to be able to get some
>> context in the callback?
>
> In your case, with a single-threaded app with C++ lambda captured
> variables, you wouldn't need the library to do that. In a
> multithreaded app's case, __thread variables and the promise to call
> those functions back from the calling thread should again let one get
> context if required.
Hmm does it actually work to capture some variables in the C++ lambda?
Given that the callback is declared as a simple function pointer:
64 typedef int (*debuginfod_progressfn_t)(long a, long b);
65 debuginfod_progressfn_t debuginfod_set_progressfn(debuginfod_progressfn_t fn);
I'm not sure that we can pass a lambda that captures stuff. Just like this program:
static void func(void (*callback)(void)) { callback(); }
int main() { int a; func([a] { }); return 0; }
Generates this error:
test.cpp: In function ‘int main()’:
test.cpp:2:33: error: cannot convert ‘main()::<lambda()>’ to ‘void (*)()’
2 | int main() { int a; func([a] { }); return 0; }
| ^
| |
| main()::<lambda()>
test.cpp:1:25: note: initializing argument 1 of ‘void func(void (*)())’
1 | static void func(void (*callback)(void)) { callback(); }
| ~~~~~~~^~~~~~~~~~~~~~~
>> I am noticing that debuginfod calls don't have any "context" or "handle"
>> parameters, which could suggest that the state of the library (if there
>> is any) is kept as global variables. [...]
I think that providing a void pointer for context is pretty standard thing
for C libraries that accept callbacks. I would use __thread and the promise
to call the function back in the same thread to "retro-fit" some thread-safety
in an existing API that doesn't provide a context pointer, and that can't be
changed. But if the API is new, I think the context pointer solution is more
obvious for the user.
> It turns out it's the opposite: except for this callback function
> pointer, it's practically all local variables therefore multithread-safe.
Ok, well I think it would be a good reason to adopt an API of the style:
debuginfod_client *client = debuginfod_create_client ();
debuginfod_set_progressfn (client, my_progress_cb);
and where you pass `client` to all further calls. That client object would
keep the callback for those calls, but also any other state that you might
want to keep across in the future. Again, this is easy to add in the
beginning, but hard to retro-fit later on.
Simon
next prev parent reply other threads:[~2019-11-05 15:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 20:28 Aaron Merey
2019-09-13 21:03 ` Tom Tromey
2019-09-22 3:53 ` Christian Biesinger via gdb-patches
2019-10-09 14:55 ` Tom Tromey
2019-10-28 20:34 ` Aaron Merey
2019-11-01 19:31 ` Tom Tromey
2019-11-01 21:03 ` Aaron Merey
2019-11-02 14:05 ` Frank Ch. Eigler
2019-11-04 15:03 ` Frank Ch. Eigler
2019-11-04 15:46 ` Simon Marchi
2019-11-04 16:26 ` Frank Ch. Eigler
2019-11-05 1:59 ` Aaron Merey
2019-11-05 5:27 ` Simon Marchi
2019-11-05 10:25 ` Frank Ch. Eigler
2019-11-05 15:19 ` Simon Marchi [this message]
2019-11-05 15:50 ` Frank Ch. Eigler
2019-11-05 5:35 ` Simon Marchi
2019-11-07 23:24 ` Aaron Merey
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=e05b912e-5a5e-afb7-1182-016e03ef15d1@simark.ca \
--to=simark@simark.ca \
--cc=amerey@redhat.com \
--cc=cbiesinger@google.com \
--cc=fche@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/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