Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* "maint print arch" causing gdb crash
@ 2012-10-05 14:15 ali_anwar
  2012-10-05 22:05 ` Stan Shebs
  2012-10-07  9:07 ` Yao Qi
  0 siblings, 2 replies; 5+ messages in thread
From: ali_anwar @ 2012-10-05 14:15 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

Hi,

'gdbarch_dump' is in some cases passing a NULL pointer to 'sprintf' when 
printing 'gdbarch->stap_gdb_register_suffix' etc.  Printing NULL 
pointers like this is undefined behavior.  With glibc passing a NULL 
pointer just prints "(null)". With the MSVC libc, however, GDB crashes.

Attached patch fixes this issue using the similar approach discussed in 
following scenario:
http://sourceware.org/ml/gdb-patches/2011-10/msg00662.html

There are some newly added variables due to which "maint print arch" 
command was causing gdb crash on whindows host. This patch takes care of 
them.

OK?

Thanks,
-Ali

[-- Attachment #2: gdb_crash.patch --]
[-- Type: text/x-patch, Size: 6359 bytes --]

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/ChangeLog,v
retrieving revision 1.1037
diff -u -r1.1037 ChangeLog
--- ChangeLog	29 Sep 2012 15:35:50 -0000	1.1037
+++ ChangeLog	5 Oct 2012 12:48:14 -0000
@@ -1,3 +1,10 @@
+2012-10-05  Ali Anwar  <ali_anwar@codesourcery.com>
+
+	gdb/
+	* gdbarch.sh (function_list): Use 'pstring' when printing
+	variable which could return NULL.
+	* gdbarch.c: Regenerate.
+
 2012-09-28  Ian Lance Taylor  <iant@google.com>
 
 	* Makefile.def: Make all-target-libgo depend on
Index: gdb/gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.495
diff -u -r1.495 gdbarch.c
--- gdb/gdbarch.c	2 Aug 2012 09:36:38 -0000	1.495
+++ gdb/gdbarch.c	5 Oct 2012 12:48:15 -0000
@@ -1315,16 +1315,16 @@
                       host_address_to_string (gdbarch->stabs_argument_has_addr));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_gdb_register_prefix = %s\n",
-                      gdbarch->stap_gdb_register_prefix);
+                      pstring (gdbarch->stap_gdb_register_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_gdb_register_suffix = %s\n",
-                      gdbarch->stap_gdb_register_suffix);
+                      pstring (gdbarch->stap_gdb_register_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_integer_prefix = %s\n",
-                      gdbarch->stap_integer_prefix);
+                      pstring (gdbarch->stap_integer_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_integer_suffix = %s\n",
-                      gdbarch->stap_integer_suffix);
+                      pstring (gdbarch->stap_integer_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_stap_is_single_operand_p() = %d\n",
                       gdbarch_stap_is_single_operand_p (gdbarch));
@@ -1339,16 +1339,16 @@
                       host_address_to_string (gdbarch->stap_parse_special_token));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_indirection_prefix = %s\n",
-                      gdbarch->stap_register_indirection_prefix);
+                      pstring (gdbarch->stap_register_indirection_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_indirection_suffix = %s\n",
-                      gdbarch->stap_register_indirection_suffix);
+                      pstring (gdbarch->stap_register_indirection_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_prefix = %s\n",
-                      gdbarch->stap_register_prefix);
+                      pstring (gdbarch->stap_register_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_suffix = %s\n",
-                      gdbarch->stap_register_suffix);
+                      pstring (gdbarch->stap_register_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_static_transform_name_p() = %d\n",
                       gdbarch_static_transform_name_p (gdbarch));
Index: gdb/gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.544
diff -u -r1.544 gdbarch.sh
--- gdb/gdbarch.sh	2 Aug 2012 09:36:39 -0000	1.544
+++ gdb/gdbarch.sh	5 Oct 2012 12:48:16 -0000
@@ -809,10 +809,10 @@
 #  \$10 ;; integer constant 10
 #
 # in this case, this prefix would be the character \`\$\'.
-v:const char *:stap_integer_prefix:::0:0::0:gdbarch->stap_integer_prefix
+v:const char *:stap_integer_prefix:::0:0::0:pstring (gdbarch->stap_integer_prefix)
 
 # Suffix used to mark an integer constant on the architecture's assembly.
-v:const char *:stap_integer_suffix:::0:0::0:gdbarch->stap_integer_suffix
+v:const char *:stap_integer_suffix:::0:0::0:pstring (gdbarch->stap_integer_suffix)
 
 # Prefix used to mark a register name on the architecture's assembly.
 # For example, on x86 the register name is written as:
@@ -820,10 +820,10 @@
 #  \%eax ;; register eax
 #
 # in this case, this prefix would be the character \`\%\'.
-v:const char *:stap_register_prefix:::0:0::0:gdbarch->stap_register_prefix
+v:const char *:stap_register_prefix:::0:0::0:pstring (gdbarch->stap_register_prefix)
 
 # Suffix used to mark a register name on the architecture's assembly
-v:const char *:stap_register_suffix:::0:0::0:gdbarch->stap_register_suffix
+v:const char *:stap_register_suffix:::0:0::0:pstring (gdbarch->stap_register_suffix)
 
 # Prefix used to mark a register indirection on the architecture's assembly.
 # For example, on x86 the register indirection is written as:
@@ -834,7 +834,7 @@
 #
 # Please note that we use the indirection prefix also for register
 # displacement, e.g., \`4\(\%eax\)\' on x86.
-v:const char *:stap_register_indirection_prefix:::0:0::0:gdbarch->stap_register_indirection_prefix
+v:const char *:stap_register_indirection_prefix:::0:0::0:pstring (gdbarch->stap_register_indirection_prefix)
 
 # Suffix used to mark a register indirection on the architecture's assembly.
 # For example, on x86 the register indirection is written as:
@@ -845,7 +845,7 @@
 #
 # Please note that we use the indirection suffix also for register
 # displacement, e.g., \`4\(\%eax\)\' on x86.
-v:const char *:stap_register_indirection_suffix:::0:0::0:gdbarch->stap_register_indirection_suffix
+v:const char *:stap_register_indirection_suffix:::0:0::0:pstring (gdbarch->stap_register_indirection_suffix)
 
 # Prefix used to name a register using GDB's nomenclature.
 #
@@ -853,10 +853,10 @@
 # language (e.g., \`10\' is the 10th general-purpose register).  However,
 # inside GDB this same register has an \`r\' appended to its name, so the 10th
 # register would be represented as \`r10\' internally.
-v:const char *:stap_gdb_register_prefix:::0:0::0:gdbarch->stap_gdb_register_prefix
+v:const char *:stap_gdb_register_prefix:::0:0::0:pstring (gdbarch->stap_gdb_register_prefix)
 
 # Suffix used to name a register using GDB's nomenclature.
-v:const char *:stap_gdb_register_suffix:::0:0::0:gdbarch->stap_gdb_register_suffix
+v:const char *:stap_gdb_register_suffix:::0:0::0:pstring (gdbarch->stap_gdb_register_suffix)

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

* Re: "maint print arch" causing gdb crash
  2012-10-05 14:15 "maint print arch" causing gdb crash ali_anwar
@ 2012-10-05 22:05 ` Stan Shebs
  2012-10-07  9:07 ` Yao Qi
  1 sibling, 0 replies; 5+ messages in thread
From: Stan Shebs @ 2012-10-05 22:05 UTC (permalink / raw)
  To: gdb-patches

On 10/5/12 7:13 AM, ali_anwar wrote:
> Hi,
>
> 'gdbarch_dump' is in some cases passing a NULL pointer to 'sprintf' 
> when printing 'gdbarch->stap_gdb_register_suffix' etc.  Printing NULL 
> pointers like this is undefined behavior. With glibc passing a NULL 
> pointer just prints "(null)". With the MSVC libc, however, GDB crashes.
>
> Attached patch fixes this issue using the similar approach discussed 
> in following scenario:
> http://sourceware.org/ml/gdb-patches/2011-10/msg00662.html
>
> There are some newly added variables due to which "maint print arch" 
> command was causing gdb crash on whindows host. This patch takes care 
> of them.
>
> OK?

Yes please, this is good!

Stan
stan@codesourcery.com


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

* Re: "maint print arch" causing gdb crash
  2012-10-05 14:15 "maint print arch" causing gdb crash ali_anwar
  2012-10-05 22:05 ` Stan Shebs
@ 2012-10-07  9:07 ` Yao Qi
  2012-10-08 11:47   ` ali_anwar
  1 sibling, 1 reply; 5+ messages in thread
From: Yao Qi @ 2012-10-07  9:07 UTC (permalink / raw)
  To: ali_anwar; +Cc: gdb-patches

On 10/05/2012 10:13 PM, ali_anwar wrote:

> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/src/src/ChangeLog,v

Hi, Ali,
You should record your change in src/gdb/ChangLog instead of the 
top-level one (src/ChangLog).

> retrieving revision 1.1037
> diff -u -r1.1037 ChangeLog
> --- ChangeLog	29 Sep 2012 15:35:50 -0000	1.1037
> +++ ChangeLog	5 Oct 2012 12:48:14 -0000
> @@ -1,3 +1,10 @@
> +2012-10-05  Ali Anwar<ali_anwar@codesourcery.com>
> +
> +	gdb/
         ^^^^ it is not needed since we put changelog entry to 
src/gdb/ChangeLog.

> +	* gdbarch.sh (function_list): Use 'pstring' when printing
> +	variable which could return NULL.
> +	* gdbarch.c: Regenerate.
> +
>   2012-09-28  Ian Lance Taylor<iant@google.com>
>
>   	* Makefile.def: Make all-target-libgo depend on

-- 
Yao


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

* Re: "maint print arch" causing gdb crash
  2012-10-07  9:07 ` Yao Qi
@ 2012-10-08 11:47   ` ali_anwar
  2012-10-08 13:12     ` Yao Qi
  0 siblings, 1 reply; 5+ messages in thread
From: ali_anwar @ 2012-10-08 11:47 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 876 bytes --]

On 10/07/2012 02:07 PM, Yao Qi wrote:
> On 10/05/2012 10:13 PM, ali_anwar wrote:
>
>> Index: ChangeLog
>> ===================================================================
>> RCS file: /cvs/src/src/ChangeLog,v
>
> Hi, Ali,
> You should record your change in src/gdb/ChangLog instead of the
> top-level one (src/ChangLog).
>

Thanks Yao. Please find attached the updated patch. Please also note 
that its my first patch for gdb. I might not have the commit rights. 
What you suggest should I do under such circumstances?

>> retrieving revision 1.1037
>> diff -u -r1.1037 ChangeLog
>> --- ChangeLog 29 Sep 2012 15:35:50 -0000 1.1037
>> +++ ChangeLog 5 Oct 2012 12:48:14 -0000
>> @@ -1,3 +1,10 @@
>> +2012-10-05 Ali Anwar<ali_anwar@codesourcery.com>
>> +
>> + gdb/
> ^^^^ it is not needed since we put changelog entry to src/gdb/ChangeLog.

Also removed "gdb/".

Thanks,
-Ali

[-- Attachment #2: gdb_crash.patch --]
[-- Type: text/x-patch, Size: 6405 bytes --]

Index: gdb/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.14728
diff -u -r1.14728 ChangeLog
--- gdb/ChangeLog	6 Oct 2012 21:10:29 -0000	1.14728
+++ gdb/ChangeLog	8 Oct 2012 11:39:39 -0000
@@ -1,3 +1,9 @@
+2012-10-08  Ali Anwar  <ali_anwar@codesourcery.com>
+
+	* gdbarch.sh (function_list): Use 'pstring' when printing
+	variable which could return NULL.
+	* gdbarch.c: Regenerate.
+
 2012-10-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	Fix crash during stepping on ppc32.
Index: gdb/gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.495
diff -u -r1.495 gdbarch.c
--- gdb/gdbarch.c	2 Aug 2012 09:36:38 -0000	1.495
+++ gdb/gdbarch.c	8 Oct 2012 11:39:40 -0000
@@ -1315,16 +1315,16 @@
                       host_address_to_string (gdbarch->stabs_argument_has_addr));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_gdb_register_prefix = %s\n",
-                      gdbarch->stap_gdb_register_prefix);
+                      pstring (gdbarch->stap_gdb_register_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_gdb_register_suffix = %s\n",
-                      gdbarch->stap_gdb_register_suffix);
+                      pstring (gdbarch->stap_gdb_register_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_integer_prefix = %s\n",
-                      gdbarch->stap_integer_prefix);
+                      pstring (gdbarch->stap_integer_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_integer_suffix = %s\n",
-                      gdbarch->stap_integer_suffix);
+                      pstring (gdbarch->stap_integer_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_stap_is_single_operand_p() = %d\n",
                       gdbarch_stap_is_single_operand_p (gdbarch));
@@ -1339,16 +1339,16 @@
                       host_address_to_string (gdbarch->stap_parse_special_token));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_indirection_prefix = %s\n",
-                      gdbarch->stap_register_indirection_prefix);
+                      pstring (gdbarch->stap_register_indirection_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_indirection_suffix = %s\n",
-                      gdbarch->stap_register_indirection_suffix);
+                      pstring (gdbarch->stap_register_indirection_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_prefix = %s\n",
-                      gdbarch->stap_register_prefix);
+                      pstring (gdbarch->stap_register_prefix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: stap_register_suffix = %s\n",
-                      gdbarch->stap_register_suffix);
+                      pstring (gdbarch->stap_register_suffix));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_static_transform_name_p() = %d\n",
                       gdbarch_static_transform_name_p (gdbarch));
Index: gdb/gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.544
diff -u -r1.544 gdbarch.sh
--- gdb/gdbarch.sh	2 Aug 2012 09:36:39 -0000	1.544
+++ gdb/gdbarch.sh	8 Oct 2012 11:39:41 -0000
@@ -809,10 +809,10 @@
 #  \$10 ;; integer constant 10
 #
 # in this case, this prefix would be the character \`\$\'.
-v:const char *:stap_integer_prefix:::0:0::0:gdbarch->stap_integer_prefix
+v:const char *:stap_integer_prefix:::0:0::0:pstring (gdbarch->stap_integer_prefix)
 
 # Suffix used to mark an integer constant on the architecture's assembly.
-v:const char *:stap_integer_suffix:::0:0::0:gdbarch->stap_integer_suffix
+v:const char *:stap_integer_suffix:::0:0::0:pstring (gdbarch->stap_integer_suffix)
 
 # Prefix used to mark a register name on the architecture's assembly.
 # For example, on x86 the register name is written as:
@@ -820,10 +820,10 @@
 #  \%eax ;; register eax
 #
 # in this case, this prefix would be the character \`\%\'.
-v:const char *:stap_register_prefix:::0:0::0:gdbarch->stap_register_prefix
+v:const char *:stap_register_prefix:::0:0::0:pstring (gdbarch->stap_register_prefix)
 
 # Suffix used to mark a register name on the architecture's assembly
-v:const char *:stap_register_suffix:::0:0::0:gdbarch->stap_register_suffix
+v:const char *:stap_register_suffix:::0:0::0:pstring (gdbarch->stap_register_suffix)
 
 # Prefix used to mark a register indirection on the architecture's assembly.
 # For example, on x86 the register indirection is written as:
@@ -834,7 +834,7 @@
 #
 # Please note that we use the indirection prefix also for register
 # displacement, e.g., \`4\(\%eax\)\' on x86.
-v:const char *:stap_register_indirection_prefix:::0:0::0:gdbarch->stap_register_indirection_prefix
+v:const char *:stap_register_indirection_prefix:::0:0::0:pstring (gdbarch->stap_register_indirection_prefix)
 
 # Suffix used to mark a register indirection on the architecture's assembly.
 # For example, on x86 the register indirection is written as:
@@ -845,7 +845,7 @@
 #
 # Please note that we use the indirection suffix also for register
 # displacement, e.g., \`4\(\%eax\)\' on x86.
-v:const char *:stap_register_indirection_suffix:::0:0::0:gdbarch->stap_register_indirection_suffix
+v:const char *:stap_register_indirection_suffix:::0:0::0:pstring (gdbarch->stap_register_indirection_suffix)
 
 # Prefix used to name a register using GDB's nomenclature.
 #
@@ -853,10 +853,10 @@
 # language (e.g., \`10\' is the 10th general-purpose register).  However,
 # inside GDB this same register has an \`r\' appended to its name, so the 10th
 # register would be represented as \`r10\' internally.
-v:const char *:stap_gdb_register_prefix:::0:0::0:gdbarch->stap_gdb_register_prefix
+v:const char *:stap_gdb_register_prefix:::0:0::0:pstring (gdbarch->stap_gdb_register_prefix)
 
 # Suffix used to name a register using GDB's nomenclature.
-v:const char *:stap_gdb_register_suffix:::0:0::0:gdbarch->stap_gdb_register_suffix
+v:const char *:stap_gdb_register_suffix:::0:0::0:pstring (gdbarch->stap_gdb_register_suffix)
 
 # Check if S is a single operand.
 #

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

* Re: "maint print arch" causing gdb crash
  2012-10-08 11:47   ` ali_anwar
@ 2012-10-08 13:12     ` Yao Qi
  0 siblings, 0 replies; 5+ messages in thread
From: Yao Qi @ 2012-10-08 13:12 UTC (permalink / raw)
  To: ali_anwar; +Cc: gdb-patches

On 10/08/2012 07:44 PM, ali_anwar wrote:

The changelog looks good to me.  Thanks.

> Thanks Yao. Please find attached the updated patch. Please also note
> that its my first patch for gdb. I might not have the commit rights.
> What you suggest should I do under such circumstances?

Mentor has a corporate assignment, so you don't have to do that.  What 
you need is a sourceware account.  With that account, you can commit 
this patch by yourself.  You can submit your account request here,

   http://sourceware.org/cgi-bin/pdw/ps_form.cgi

In that form, you'll fill in the mail address of people who approve your 
access.  Maybe Stan can approve your access, because he approved this 
patch. :)

-- 
Yao


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

end of thread, other threads:[~2012-10-08 13:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-05 14:15 "maint print arch" causing gdb crash ali_anwar
2012-10-05 22:05 ` Stan Shebs
2012-10-07  9:07 ` Yao Qi
2012-10-08 11:47   ` ali_anwar
2012-10-08 13:12     ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox