When different source files define same-name struct/union tags, crash may
resolve an unintended candidate because default type lookup depends on symbol
lookup order/context.
This series adds `struct/union -F <file_name>` to constrain datatype lookup to
the compilation-unit scope matched by the requested source file.
For example, this avoids ambiguity for duplicate tags such as
`arm_smmu_device` defined in both `arm-smmu.c` and `arm-smmu-v3.c`.
Implementation summary:
- Parse `-F` in `struct`/`union` command path and propagate `source_file` in
gdb requests.
- In gdb-side patch code, map source file -> unique scope block
(`objfile -> compunit -> filetabs -> blockvector`), prefer `STATIC_BLOCK`
and fallback to `GLOBAL_BLOCK`.
- Apply the scope temporarily for the request and restore previous scope
automatically afterward.
- If file match is missing or ambiguous, fail explicitly instead of choosing a
random candidate.
- Note: `-F` may add a small lookup-time overhead due to extra scope scanning
and symbol-table expansion needed for deterministic file-scoped matching.
Compatibility:
- Existing behavior is unchanged when `-F` is not used.
- Existing `STRUCT_SIZE/MEMBER_OFFSET/...` call paths remain compatible.
- For external/plugin callers that need file-scoped lookup with minimal changes,
expose two helper APIs:
- `char *set_temporary_datatype_filename(const char *source_file);`
- `void restore_datatype_filename(char *saved_source_file);`
chahuan (1):
struct: add -F source-file scoping for duplicate datatype names
cmdline.c | 1 +
defs.h | 4 ++
gdb-16.2.patch | 166 ++++++++++++++++++++++++++++++++++++++++++++++--
gdb_interface.c | 6 ++
help.c | 8 ++-
symbols.c | 31 ++++++++-
6 files changed, 206 insertions(+), 10 deletions(-)
--
2.43.0