#include "defs.h"
#include "windows-tdep.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include "xml-support.h"
#include "gdbarch.h"
#include "target.h"
static bool maint_display_all_tib = false;
-static struct gdbarch_data *windows_gdbarch_data_handle;
-
struct windows_gdbarch_data
{
- struct type *siginfo_type;
- struct type *tib_ptr_type; /* Type of thread information block */
+ struct type *siginfo_type = nullptr;
+ /* Type of thread information block. */
+ struct type *tib_ptr_type = nullptr;
};
-/* Allocate windows_gdbarch_data for an arch. */
-
-static void *
-init_windows_gdbarch_data (struct gdbarch *gdbarch)
-{
- return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct windows_gdbarch_data);
-}
+static const registry<gdbarch>::key<windows_gdbarch_data>
+ windows_gdbarch_data_handle;
/* Get windows_gdbarch_data of an arch. */
static struct windows_gdbarch_data *
get_windows_gdbarch_data (struct gdbarch *gdbarch)
{
- return ((struct windows_gdbarch_data *)
- gdbarch_data (gdbarch, windows_gdbarch_data_handle));
+ windows_gdbarch_data *result = windows_gdbarch_data_handle.get (gdbarch);
+ if (result == nullptr)
+ result = windows_gdbarch_data_handle.emplace (gdbarch);
+ return result;
}
/* Define Thread Local Base pointer type. */
if (target_get_tib_address (ptid, &thread_local_base) == 0)
{
- printf_filtered (_("Unable to get thread local base for %s\n"),
- target_pid_to_str (ptid).c_str ());
+ gdb_printf (_("Unable to get thread local base for %s\n"),
+ target_pid_to_str (ptid).c_str ());
return -1;
}
if (target_read (current_inferior ()->top_target (), TARGET_OBJECT_MEMORY,
NULL, tib, thread_local_base, tib_size) != tib_size)
{
- printf_filtered (_("Unable to read thread information "
- "block for %s at address %s\n"),
- target_pid_to_str (ptid).c_str (),
- paddress (target_gdbarch (), thread_local_base));
+ gdb_printf (_("Unable to read thread information "
+ "block for %s at address %s\n"),
+ target_pid_to_str (ptid).c_str (),
+ paddress (target_gdbarch (), thread_local_base));
return -1;
}
- printf_filtered (_("Thread Information Block %s at %s\n"),
- target_pid_to_str (ptid).c_str (),
- paddress (target_gdbarch (), thread_local_base));
+ gdb_printf (_("Thread Information Block %s at %s\n"),
+ target_pid_to_str (ptid).c_str (),
+ paddress (target_gdbarch (), thread_local_base));
index = (gdb_byte *) tib;
{
val = extract_unsigned_integer (index, size, byte_order);
if (i < max_name)
- printf_filtered (_("%s is 0x%s\n"), TIB_NAME[i], phex (val, size));
+ gdb_printf (_("%s is 0x%s\n"), TIB_NAME[i], phex (val, size));
else if (val != 0)
- printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i * size, 2),
- phex (val, size));
+ gdb_printf (_("TIB[0x%s] is 0x%s\n"), phex (i * size, 2),
+ phex (val, size));
index += size;
}
return 1;
static void
windows_iterate_over_objfiles_in_search_order
- (struct gdbarch *gdbarch,
- iterate_over_objfiles_in_search_order_cb_ftype *cb,
- void *cb_data, struct objfile *current_objfile)
+ (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb,
+ objfile *current_objfile)
{
- int stop;
-
if (current_objfile)
{
- stop = cb (current_objfile, cb_data);
- if (stop)
+ if (cb (current_objfile))
return;
}
for (objfile *objfile : current_program_space->objfiles ())
- {
- if (objfile != current_objfile)
- {
- stop = cb (objfile, cb_data);
- if (stop)
- return;
- }
- }
+ if (objfile != current_objfile)
+ {
+ if (cb (objfile))
+ return;
+ }
}
static void
show_maint_show_all_tib (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("Show all non-zero elements of "
- "Thread Information Block is %s.\n"), value);
+ gdb_printf (file, _("Show all non-zero elements of "
+ "Thread Information Block is %s.\n"), value);
}
{
tlb_make_value,
NULL,
- NULL
};
/* Layout of an element of a PE's Import Directory Table. Based on:
|| import_table_va >= idata_section_end_va)
{
warning (_("\
-%s: import table's virtual address (0x%" BFD_VMA_FMT "x) is outside .idata \
-section's range [0x%" BFD_VMA_FMT "x, 0x%" BFD_VMA_FMT "x[."),
- bfd_get_filename (abfd), import_table_va, idata_section_va,
- idata_section_end_va);
+%s: import table's virtual address (%s) is outside .idata \
+section's range [%s, %s]."),
+ bfd_get_filename (abfd), hex_string (import_table_va),
+ hex_string (idata_section_va),
+ hex_string (idata_section_end_va));
return false;
}
if (name_va < idata_section_va || name_va >= idata_section_end_va)
{
warning (_("\
-%s: name's virtual address (0x%" BFD_VMA_FMT "x) is outside .idata section's \
-range [0x%" BFD_VMA_FMT "x, 0x%" BFD_VMA_FMT "x[."),
- bfd_get_filename (abfd), name_va, idata_section_va,
- idata_section_end_va);
+%s: name's virtual address (%s) is outside .idata section's \
+range [%s, %s]."),
+ bfd_get_filename (abfd), hex_string (name_va),
+ hex_string (idata_section_va),
+ hex_string (idata_section_end_va));
break;
}
size_t module_name_offset;
CORE_ADDR base_addr;
- gdb_byte *buf = NULL;
-
if (!startswith (sect->name, ".module"))
return;
- buf = (gdb_byte *) xmalloc (bfd_section_size (sect) + 1);
- if (!buf)
- {
- printf_unfiltered ("memory allocation failed for %s\n", sect->name);
- goto out;
- }
+ gdb::byte_vector buf (bfd_section_size (sect) + 1);
if (!bfd_get_section_contents (abfd, sect,
- buf, 0, bfd_section_size (sect)))
- goto out;
-
-
+ buf.data (), 0, bfd_section_size (sect)))
+ return;
+ /* We're going to treat part of the buffer as a string, so make sure
+ it is NUL-terminated. */
+ buf.back () = 0;
/* A DWORD (data_type) followed by struct windows_core_module_info. */
- data_type = extract_unsigned_integer (buf, 4, byte_order);
+ if (bfd_section_size (sect) < 4)
+ return;
+ data_type = extract_unsigned_integer (buf.data (), 4, byte_order);
if (data_type == NOTE_INFO_MODULE)
{
- base_addr = extract_unsigned_integer (buf + 4, 4, byte_order);
- module_name_size = extract_unsigned_integer (buf + 8, 4, byte_order);
module_name_offset = 12;
+ if (bfd_section_size (sect) < module_name_offset)
+ return;
+ base_addr = extract_unsigned_integer (&buf[4], 4, byte_order);
+ module_name_size = extract_unsigned_integer (&buf[8], 4, byte_order);
}
else if (data_type == NOTE_INFO_MODULE64)
{
- base_addr = extract_unsigned_integer (buf + 4, 8, byte_order);
- module_name_size = extract_unsigned_integer (buf + 12, 4, byte_order);
module_name_offset = 16;
+ if (bfd_section_size (sect) < module_name_offset)
+ return;
+ base_addr = extract_unsigned_integer (&buf[4], 8, byte_order);
+ module_name_size = extract_unsigned_integer (&buf[12], 4, byte_order);
}
else
- goto out;
+ return;
if (module_name_offset + module_name_size > bfd_section_size (sect))
- goto out;
- module_name = (char *) buf + module_name_offset;
+ return;
+ module_name = (char *) buf.data () + module_name_offset;
/* The first module is the .exe itself. */
if (data->module_count != 0)
windows_xfer_shared_library (module_name, base_addr,
NULL, data->gdbarch, data->obstack);
data->module_count++;
-
-out:
- xfree (buf);
- return;
}
ULONGEST
void
_initialize_windows_tdep ()
{
- windows_gdbarch_data_handle
- = gdbarch_data_register_post_init (init_windows_gdbarch_data);
-
init_w32_command_list ();
cmd_list_element *info_w32_thread_information_block_cmd
= add_cmd ("thread-information-block", class_info, display_tib,