This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 1/2] Port gdbserver to GNU/Hurd
- From: Pedro Alves <palves at redhat dot com>
- To: Yue Lu <hacklu dot newborn at gmail dot com>
- Cc: Pedro Alves <palves at redhat dot com>, gdb-patches <gdb-patches at sourceware dot org>, Thomas Schwinge <thomas at codesourcery dot com>, Luis Machado <lgustavo at codesourcery dot com>, bug-hurd at gnu dot org
- Date: Wed, 18 Sep 2013 13:29:58 +0100
- Subject: Re: [PATCH 1/2] Port gdbserver to GNU/Hurd
- Authentication-results: sourceware.org; auth=none
- References: <CAB8fV=jJ64i91VW52ZmdnEDZhd1ZGTAykDqoFyPJanCP=5beqA at mail dot gmail dot com> <CAB8fV=iw783uGF8sWyqJNcWR0j_jaY5XO+FR3TyPatMGJ8Fdjw at mail dot gmail dot com> <87txi2i6t6 dot fsf at kepler dot schwinge dot homeip dot net> <5225C3C6 dot 8090101 at redhat dot com> <CAB8fV=gXmHSqLF14aF3RUU6paExSHft-gqySCsvyxiYELY4V+A at mail dot gmail dot com> <5228DBA7 dot 9050408 at redhat dot com> <522A2497 dot 7090405 at redhat dot com> <CAB8fV=hcYutwy7KzeJyELziBaKZio0G9ZFX=FucRWav-T2_cnA at mail dot gmail dot com>
On 09/12/2013 04:05 AM, Yue Lu wrote:
> Honestly to say, I have copied them from function gnu_xfer_memory. But
> I think, before reference a pointer, check whether it was a NULL seems
> not a bad way :-).
We don't go around checking for NULL before _every_ pointer
dereference. :-)
NULL pointer checks are used when the function's semantics
give special meaning to NULL, like for example, for optional
parameters. If that's not the function's semantics, and you still
may see a NULL pointer, then that tells there's actually a bug
that triggered already elsewhere before the function in question
was called. IOW, a NULL check in these cases is just masking out a
bug in some caller. In some cases, we might add a gdb_assert to
catch the bug in a nicer way instead of just crashing.
I suspect that what may happen is that at some point it
was possible for GDB to select a no-longer-existing-thread
(though I can't see how in the current code), and then setting
breakpoints, or other operations that require reading memory
would crash.
--
Pedro Alves