public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] compile-loc2c: Fix uninitialized variable error
@ 2017-06-10 19:49 Simon Marchi
  2017-06-25 17:24 ` Simon Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2017-06-10 19:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Compiling with clang gives this warning/error:

  /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:731:6: error: variable 'uoffset' is uninitialized when used here [-Werror,-Wuninitialized]
              uoffset += dwarf2_per_cu_text_offset (per_cu);
              ^~~~~~~
  /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:669:23: note: initialize the variable 'uoffset' to silence this warning
        uint64_t uoffset, reg;
                        ^
                         = 0

I am really not sure if what this patch does is good, but it is my best
guess.  DW_OP_addr means that there's an constant address provided by
the DWARF bytecode that should be pushed on the stack.  That address is
considered skipped by the "op_ptr += addr_size", but it is never read.
uoffset is indeed read just after, without having been assigned first.

So I think the intent is to read the address, it was just omitted.

gdb/ChangeLog:

	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
	address when op is DW_OP_addr.
---
 gdb/compile/compile-loc2c.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index a53214f..ead1003 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -722,6 +722,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
 	  break;
 
 	case DW_OP_addr:
+	  uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
 	  op_ptr += addr_size;
 	  /* Some versions of GCC emit DW_OP_addr before
 	     DW_OP_GNU_push_tls_address.  In this case the value is an
-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] compile-loc2c: Fix uninitialized variable error
  2017-06-10 19:49 [PATCH] compile-loc2c: Fix uninitialized variable error Simon Marchi
@ 2017-06-25 17:24 ` Simon Marchi
  2017-07-09 16:44   ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2017-06-25 17:24 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches, Tom Tromey

On 2017-06-10 21:49, Simon Marchi wrote:
> Compiling with clang gives this warning/error:
> 
>   /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:731:6:
> error: variable 'uoffset' is uninitialized when used here
> [-Werror,-Wuninitialized]
>               uoffset += dwarf2_per_cu_text_offset (per_cu);
>               ^~~~~~~
>   /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:669:23:
> note: initialize the variable 'uoffset' to silence this warning
>         uint64_t uoffset, reg;
>                         ^
>                          = 0
> 
> I am really not sure if what this patch does is good, but it is my best
> guess.  DW_OP_addr means that there's an constant address provided by
> the DWARF bytecode that should be pushed on the stack.  That address is
> considered skipped by the "op_ptr += addr_size", but it is never read.
> uoffset is indeed read just after, without having been assigned first.
> 
> So I think the intent is to read the address, it was just omitted.
> 
> gdb/ChangeLog:
> 
> 	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
> 	address when op is DW_OP_addr.
> ---
>  gdb/compile/compile-loc2c.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
> index a53214f..ead1003 100644
> --- a/gdb/compile/compile-loc2c.c
> +++ b/gdb/compile/compile-loc2c.c
> @@ -722,6 +722,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file 
> &stream,
>  	  break;
> 
>  	case DW_OP_addr:
> +	  uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
>  	  op_ptr += addr_size;
>  	  /* Some versions of GCC emit DW_OP_addr before
>  	     DW_OP_GNU_push_tls_address.  In this case the value is an

Hi Tom,

As you are the original author of that code, would it be possible for 
you to take a quick look, if you remember any of this :) ?

Thanks,

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] compile-loc2c: Fix uninitialized variable error
  2017-06-25 17:24 ` Simon Marchi
@ 2017-07-09 16:44   ` Tom Tromey
  2017-07-09 18:28     ` Simon Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2017-07-09 16:44 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Simon Marchi, gdb-patches, Tom Tromey

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Sorry about the delay on this.  I've been away.

>> * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
>> address when op is DW_OP_addr.

Simon> As you are the original author of that code, would it be possible for
Simon> you to take a quick look, if you remember any of this :) ?

This patch looks correct to me.  I'm sure the earlier state was just an
oversight.

FWIW in gimli's DWARF expression code, I separated the format decoder
from the evaluator to avoid this sort of problem.  Each operation is
decoded to an object; and then evaluation is done using the object.
This isn't perfect, as different users of the decoded objects can still
disagree about the semantics of the operation, but an approach like this
would have caught this bug.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] compile-loc2c: Fix uninitialized variable error
  2017-07-09 16:44   ` Tom Tromey
@ 2017-07-09 18:28     ` Simon Marchi
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2017-07-09 18:28 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Simon Marchi, gdb-patches

On 2017-07-09 18:44, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
> Sorry about the delay on this.  I've been away.
> 
>>> * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
>>> address when op is DW_OP_addr.
> 
> Simon> As you are the original author of that code, would it be 
> possible for
> Simon> you to take a quick look, if you remember any of this :) ?
> 
> This patch looks correct to me.  I'm sure the earlier state was just an
> oversight.

Thanks! Pushing it now.

> FWIW in gimli's DWARF expression code, I separated the format decoder
> from the evaluator to avoid this sort of problem.  Each operation is
> decoded to an object; and then evaluation is done using the object.
> This isn't perfect, as different users of the decoded objects can still
> disagree about the semantics of the operation, but an approach like 
> this
> would have caught this bug.

Indeed, that sounds like a good design.

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-09 18:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-10 19:49 [PATCH] compile-loc2c: Fix uninitialized variable error Simon Marchi
2017-06-25 17:24 ` Simon Marchi
2017-07-09 16:44   ` Tom Tromey
2017-07-09 18:28     ` Simon Marchi

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).