gdb: add assert in cmd_list_element::set_context
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:38:51 +0000 (21:38 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:38:51 +0000 (21:38 -0400)
If something tries to set a context pointer on a cmd_list_element and
m_context is not nullptr, it's likely that two parts of the code are
trying to set different contexts, and one will overwrite the other.
This is almost guaranteed to lead to bad behavior or a crash, as one of
the spots will not be using the data it expects.  This happened to me
during development, so I think having this assert would be useful to
catch this problem earlier.

gdb/ChangeLog:

* cli/cli-decode.h (struct cmd_list_element) <set_context>: Add
assert.

Change-Id: I1f2e9fda1bf2bec1b732c9b90e7d7910a97f2ac6

gdb/ChangeLog
gdb/cli/cli-decode.h

index c523186cdd7986cad4521cb94c269a5ad4cc3018..6ba91d8ec6ef43c6ea495dfa6cb78f0332682537 100644 (file)
@@ -1,3 +1,8 @@
+2021-06-25  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * cli/cli-decode.h (struct cmd_list_element) <set_context>: Add
+       assert.
+
 2021-06-25  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * cli/cli-decode.h (struct cmd_list_element) <set_context,
index 1692a6e28352042f085e2e0ade5b7c196ef14b80..241535ae5b5003b5f73b7bc8660de4bec4e7a290 100644 (file)
@@ -94,7 +94,10 @@ struct cmd_list_element
   { return this->func == nullptr; }
 
   void set_context (void *context)
-  { m_context = context; }
+  {
+    gdb_assert (m_context == nullptr);
+    m_context = context;
+  }
 
   void *context () const
   { return m_context; }
This page took 0.028625 seconds and 4 git commands to generate.