mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-30 00:52:16 +08:00
Change line_table methods to return unique_xmalloc_ptr
This changes the two new line_table methods to return unique_xmalloc_ptr. This removes a bit of manual memory management. 2020-02-08 Tom Tromey <tom@tromey.com> * dwarf2/read.c (struct line_header) <file_full_name, file_file_name>: Return unique_xmalloc_ptr. (line_header::file_file_name): Update. (line_header::file_full_name): Update. (dw2_get_file_names_reader): Update. (macro_start_file): Update. Change-Id: I9442dba43882fb26097d0770a291eea2b03913a4
This commit is contained in:
@ -1,3 +1,12 @@
|
|||||||
|
2020-02-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* dwarf2/read.c (struct line_header) <file_full_name,
|
||||||
|
file_file_name>: Return unique_xmalloc_ptr.
|
||||||
|
(line_header::file_file_name): Update.
|
||||||
|
(line_header::file_full_name): Update.
|
||||||
|
(dw2_get_file_names_reader): Update.
|
||||||
|
(macro_start_file): Update.
|
||||||
|
|
||||||
2020-02-08 Tom Tromey <tom@tromey.com>
|
2020-02-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* dwarf2/read.c (struct line_header) <file_full_name,
|
* dwarf2/read.c (struct line_header) <file_full_name,
|
||||||
|
@ -1078,13 +1078,14 @@ struct line_header
|
|||||||
table. Use COMP_DIR as the name of the current directory of the
|
table. Use COMP_DIR as the name of the current directory of the
|
||||||
compilation. The result is allocated using xmalloc; the caller
|
compilation. The result is allocated using xmalloc; the caller
|
||||||
is responsible for freeing it. */
|
is responsible for freeing it. */
|
||||||
char *file_full_name (int file, const char *comp_dir);
|
gdb::unique_xmalloc_ptr<char> file_full_name (int file,
|
||||||
|
const char *comp_dir);
|
||||||
|
|
||||||
/* Return file name relative to the compilation directory of file
|
/* Return file name relative to the compilation directory of file
|
||||||
number I in this object's file name table. The result is
|
number I in this object's file name table. The result is
|
||||||
allocated using xmalloc; the caller is responsible for freeing
|
allocated using xmalloc; the caller is responsible for freeing
|
||||||
it. */
|
it. */
|
||||||
char *file_file_name (int file);
|
gdb::unique_xmalloc_ptr<char> file_file_name (int file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* The include_directories table. Note these are observing
|
/* The include_directories table. Note these are observing
|
||||||
@ -3405,7 +3406,8 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
|
|||||||
if (offset != 0)
|
if (offset != 0)
|
||||||
qfn->file_names[0] = xstrdup (fnd.name);
|
qfn->file_names[0] = xstrdup (fnd.name);
|
||||||
for (int i = 0; i < lh->file_names_size (); ++i)
|
for (int i = 0; i < lh->file_names_size (); ++i)
|
||||||
qfn->file_names[i + offset] = lh->file_full_name (i + 1, fnd.comp_dir);
|
qfn->file_names[i + offset] = lh->file_full_name (i + 1,
|
||||||
|
fnd.comp_dir).release ();
|
||||||
qfn->real_names = NULL;
|
qfn->real_names = NULL;
|
||||||
|
|
||||||
lh_cu->v.quick->file_names = qfn;
|
lh_cu->v.quick->file_names = qfn;
|
||||||
@ -23754,7 +23756,7 @@ dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
|
|||||||
|
|
||||||
/* Macro support. */
|
/* Macro support. */
|
||||||
|
|
||||||
char *
|
gdb::unique_xmalloc_ptr<char>
|
||||||
line_header::file_file_name (int file)
|
line_header::file_file_name (int file)
|
||||||
{
|
{
|
||||||
/* Is the file number a valid index into the line header's file name
|
/* Is the file number a valid index into the line header's file name
|
||||||
@ -23767,9 +23769,11 @@ line_header::file_file_name (int file)
|
|||||||
{
|
{
|
||||||
const char *dir = fe->include_dir (this);
|
const char *dir = fe->include_dir (this);
|
||||||
if (dir != NULL)
|
if (dir != NULL)
|
||||||
return concat (dir, SLASH_STRING, fe->name, (char *) NULL);
|
return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
|
||||||
|
fe->name,
|
||||||
|
(char *) NULL));
|
||||||
}
|
}
|
||||||
return xstrdup (fe->name);
|
return make_unique_xstrdup (fe->name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -23784,23 +23788,24 @@ line_header::file_file_name (int file)
|
|||||||
complaint (_("bad file number in macro information (%d)"),
|
complaint (_("bad file number in macro information (%d)"),
|
||||||
file);
|
file);
|
||||||
|
|
||||||
return xstrdup (fake_name);
|
return make_unique_xstrdup (fake_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
gdb::unique_xmalloc_ptr<char>
|
||||||
line_header::file_full_name (int file, const char *comp_dir)
|
line_header::file_full_name (int file, const char *comp_dir)
|
||||||
{
|
{
|
||||||
/* Is the file number a valid index into the line header's file name
|
/* Is the file number a valid index into the line header's file name
|
||||||
table? Remember that file numbers start with one, not zero. */
|
table? Remember that file numbers start with one, not zero. */
|
||||||
if (is_valid_file_index (file))
|
if (is_valid_file_index (file))
|
||||||
{
|
{
|
||||||
char *relative = file_file_name (file);
|
gdb::unique_xmalloc_ptr<char> relative = file_file_name (file);
|
||||||
|
|
||||||
if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
|
if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL)
|
||||||
return relative;
|
return relative;
|
||||||
return reconcat (relative, comp_dir, SLASH_STRING,
|
return gdb::unique_xmalloc_ptr<char> (concat (comp_dir, SLASH_STRING,
|
||||||
relative, (char *) NULL);
|
relative.get (),
|
||||||
|
(char *) NULL));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return file_file_name (file);
|
return file_file_name (file);
|
||||||
@ -23814,7 +23819,7 @@ macro_start_file (struct dwarf2_cu *cu,
|
|||||||
struct line_header *lh)
|
struct line_header *lh)
|
||||||
{
|
{
|
||||||
/* File name relative to the compilation directory of this source file. */
|
/* File name relative to the compilation directory of this source file. */
|
||||||
char *file_name = lh->file_file_name (file);
|
gdb::unique_xmalloc_ptr<char> file_name = lh->file_file_name (file);
|
||||||
|
|
||||||
if (! current_file)
|
if (! current_file)
|
||||||
{
|
{
|
||||||
@ -23824,13 +23829,11 @@ macro_start_file (struct dwarf2_cu *cu,
|
|||||||
|
|
||||||
/* If we have no current file, then this must be the start_file
|
/* If we have no current file, then this must be the start_file
|
||||||
directive for the compilation unit's main source file. */
|
directive for the compilation unit's main source file. */
|
||||||
current_file = macro_set_main (macro_table, file_name);
|
current_file = macro_set_main (macro_table, file_name.get ());
|
||||||
macro_define_special (macro_table);
|
macro_define_special (macro_table);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
current_file = macro_include (current_file, line, file_name);
|
current_file = macro_include (current_file, line, file_name.get ());
|
||||||
|
|
||||||
xfree (file_name);
|
|
||||||
|
|
||||||
return current_file;
|
return current_file;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user