aboutsummaryrefslogtreecommitdiff
path: root/gdb/interps.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2023-03-02 15:32:23 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2023-03-07 16:30:14 -0500
commit5a8ac2cb96cdb6c470a2ad4dec6442a21aa7dae9 (patch)
tree9d94cf11a0307aacba3876c1ec687a95bf5f0b3e /gdb/interps.h
parentf4db482bac97b12de5b25c203e3d24116e2a46bb (diff)
downloadbinutils-5a8ac2cb96cdb6c470a2ad4dec6442a21aa7dae9.zip
binutils-5a8ac2cb96cdb6c470a2ad4dec6442a21aa7dae9.tar.gz
binutils-5a8ac2cb96cdb6c470a2ad4dec6442a21aa7dae9.tar.bz2
gdb: make interp::m_name an `const char *`
I realized that the memory for interp names does not need to be allocated. The name used to register interp factory functions is always a literal string, so has static storage duration. If we change interp_lookup to pass that name instead of the string that it receives as a parameter (which does not always have static storage duration), then interps can simply store pointers to the name. So, change interp_lookup to pass `factory.name` rather than `name`. Change interp::m_name to be a `const char *` rather than an std::string. Change-Id: I0474d1f7b3512e7d172ccd73018aea927def3188 Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/interps.h')
-rw-r--r--gdb/interps.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/gdb/interps.h b/gdb/interps.h
index 01bec47..62f3795 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -32,7 +32,9 @@ typedef struct interp *(*interp_factory_func) (const char *name);
/* Each interpreter kind (CLI, MI, etc.) registers itself with a call
to this function, passing along its name, and a pointer to a
function that creates a new instance of an interpreter with that
- name. */
+ name.
+
+ The memory for NAME must have static storage duration. */
extern void interp_factory_register (const char *name,
interp_factory_func func);
@@ -76,13 +78,11 @@ public:
{ return false; }
const char *name () const
- {
- return m_name.get ();
- }
+ { return m_name; }
private:
- /* This is the name in "-i=" and "set interpreter". */
- gdb::unique_xmalloc_ptr<char> m_name;
+ /* The memory for this is static, it comes from literal strings (e.g. "cli"). */
+ const char *m_name;
public:
/* Interpreters are stored in a linked list, this is the next