diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2017-12-06 16:27:33 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-12-06 16:37:29 -0500 |
commit | 9a93831ccc0ba3ba447552069f230e6d93dcbf3f (patch) | |
tree | 32472c683e9c5e79e16e7ec0ec61c56f59bb3f5b /gdb/break-catch-syscall.c | |
parent | 1c9c7ce078427891a94dc7604ce9e62175ebfda5 (diff) | |
download | gdb-9a93831ccc0ba3ba447552069f230e6d93dcbf3f.zip gdb-9a93831ccc0ba3ba447552069f230e6d93dcbf3f.tar.gz gdb-9a93831ccc0ba3ba447552069f230e6d93dcbf3f.tar.bz2 |
Fix syscall group completion
The test gdb.base/catch-syscall.exp has been failing since commit
3d415c26bad3a15eed00d2ddf85c4268df77a4cc
Remove cleanups from break-catch-syscall.c
The reason is that we are putting into the group_ptr array a pointer to
the buffer of the local string object. If the string is small enough to
fit in the internal string buffer (used for small string optimizations),
the pointer will point to the local object directly. So even if we
std::move the string to the vector, the pointer in group_ptr will still
point to the local object. When we reuse that object (technically a new
instance, but most likely the same memory) for the next syscall, we'll
overwrite the previous string. The result is that we'll get less
results than expected, since there will be duplicates.
We'll also run into problems if we push the string to the vector, and
then record the c_str () pointer using the string object in the vector.
The vector might get reallocated, the string may move in memory, and our
pointer in group_ptr will point to stale memory.
Instead, we have to push all the strings first, then, when we know the
vector won't change anymore, build the group_ptr array. This is what
this patch does.
gdb/ChangeLog:
* break-catch-syscall.c (catch_syscall_completer): Get pointers
to syscall group strings after building the string vector.
Diffstat (limited to 'gdb/break-catch-syscall.c')
-rw-r--r-- | gdb/break-catch-syscall.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index a8312f2..dd7b379 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -559,7 +559,6 @@ catch_syscall_completer (struct cmd_list_element *cmd, struct gdbarch *gdbarch = get_current_arch (); gdb::unique_xmalloc_ptr<const char *> group_list; const char *prefix; - int i; /* Completion considers ':' to be a word separator, so we use this to verify whether the previous word was a group prefix. If so, we @@ -587,14 +586,11 @@ catch_syscall_completer (struct cmd_list_element *cmd, std::vector<std::string> holders; /* Append "group:" prefix to syscall groups. */ - for (i = 0; group_ptr[i] != NULL; i++) - { - std::string prefixed_group = string_printf ("group:%s", - group_ptr[i]); + for (int i = 0; group_ptr[i] != NULL; i++) + holders.push_back (string_printf ("group:%s", group_ptr[i])); - group_ptr[i] = prefixed_group.c_str (); - holders.push_back (std::move (prefixed_group)); - } + for (int i = 0; group_ptr[i] != NULL; i++) + group_ptr[i] = holders[i].c_str (); if (syscall_list != NULL) complete_on_enum (tracker, syscall_list.get (), word, word); |