Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA/commit(Ada)] SEGV during symbol completion - VEC usage issue
Date: Thu, 07 Feb 2008 22:26:00 -0000	[thread overview]
Message-ID: <20080207222459.GF3907@adacore.com> (raw)

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

It's weird that I didn't spot this problem earlier: When the number
of possible completions exceeds 128 (the initial size of the VEC
we use to store all completions), the debugger segfaults.

The problem, I think, is that I didn't understand how VEC_safe_push
works underneath. I didn't realize that this routine would change
the value of the given VEC*, I thought it would only change the
underlying record.

I used to have:

    procedure bla (VEC(char_ptr) *sv, ...)
    {
      ...
      VEC_safe_push (char_ptr, sv, some_string);
    }

When SV had to be expanded, the value of SV ended up being changed,
but this new address was never propagated back to the caller.

So I fixed the problem by turning parameter SV into a VEC**.

2008-02-07  Joel Brobecker  <brobecker@adacore.com>

        * ada-lang.c (symbol_completion_add): Make SV parameter a VEC**
        instead of just a VEC*. Update use of SV.
        (ada_make_symbol_completion_list): Update symbol_completion_add calls.

Tested on x86-linux, no regression. I'll commit now because it cures a SEGV
that is easy to hit, but I'd appreciate a second pair of eyes...

Thanks,
-- 
Joel

[-- Attachment #2: VEC.diff --]
[-- Type: text/plain, Size: 3106 bytes --]

Index: ada-lang.c
===================================================================
--- ada-lang.c	(revision 167)
+++ ada-lang.c	(revision 168)
@@ -5498,7 +5498,7 @@ DEF_VEC_P (char_ptr);
    encoded).  */
 
 static void
-symbol_completion_add (VEC(char_ptr) *sv,
+symbol_completion_add (VEC(char_ptr) **sv,
                        const char *sym_name,
                        const char *text, int text_len,
                        const char *orig_text, const char *word,
@@ -5534,7 +5534,7 @@ symbol_completion_add (VEC(char_ptr) *sv
       strcat (completion, match);
     }
 
-  VEC_safe_push (char_ptr, sv, completion);
+  VEC_safe_push (char_ptr, *sv, completion);
 }
 
 /* Return a list of possible symbol names completing TEXT0.  The list
@@ -5597,7 +5597,7 @@ ada_make_symbol_completion_list (char *t
                  + ps->n_global_syms); psym++)
       {
         QUIT;
-        symbol_completion_add (completions, SYMBOL_LINKAGE_NAME (*psym),
+        symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (*psym),
                                text, text_len, text0, word,
                                wild_match, encoded);
       }
@@ -5607,7 +5607,7 @@ ada_make_symbol_completion_list (char *t
                  + ps->n_static_syms); psym++)
       {
         QUIT;
-        symbol_completion_add (completions, SYMBOL_LINKAGE_NAME (*psym),
+        symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (*psym),
                                text, text_len, text0, word,
                                wild_match, encoded);
       }
@@ -5621,7 +5621,7 @@ ada_make_symbol_completion_list (char *t
   ALL_MSYMBOLS (objfile, msymbol)
   {
     QUIT;
-    symbol_completion_add (completions, SYMBOL_LINKAGE_NAME (msymbol),
+    symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (msymbol),
                            text, text_len, text0, word, wild_match, encoded);
   }
 
@@ -5635,7 +5635,7 @@ ada_make_symbol_completion_list (char *t
 
       ALL_BLOCK_SYMBOLS (b, iter, sym)
       {
-        symbol_completion_add (completions, SYMBOL_LINKAGE_NAME (sym),
+        symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
                                text, text_len, text0, word,
                                wild_match, encoded);
       }
@@ -5650,7 +5650,7 @@ ada_make_symbol_completion_list (char *t
     b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
     ALL_BLOCK_SYMBOLS (b, iter, sym)
     {
-      symbol_completion_add (completions, SYMBOL_LINKAGE_NAME (sym),
+      symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
                              text, text_len, text0, word,
                              wild_match, encoded);
     }
@@ -5665,7 +5665,7 @@ ada_make_symbol_completion_list (char *t
       continue;
     ALL_BLOCK_SYMBOLS (b, iter, sym)
     {
-      symbol_completion_add (completions, SYMBOL_LINKAGE_NAME (sym),
+      symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
                              text, text_len, text0, word,
                              wild_match, encoded);
     }

             reply	other threads:[~2008-02-07 22:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-07 22:26 Joel Brobecker [this message]
2008-02-07 22:54 ` Daniel Jacobowitz

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=20080207222459.GF3907@adacore.com \
    --to=brobecker@adacore.com \
    --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