Skip to content

Commit ce74123

Browse files
committed
Adding option
--format-universalnumber=<n> so if reading a Mach-O universal binary one can select which executable from that universal binary libdwarf should read. modified: src/bin/dwarfdump/dd_command_options.c modified: src/bin/dwarfdump/dd_glflags.c modified: src/bin/dwarfdump/dd_glflags.h modified: src/bin/dwarfdump/dwarfdump.c
1 parent f60c9e7 commit ce74123

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

src/bin/dwarfdump/dd_command_options.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ static void arg_format_suppress_utf8(void);
358358
static void arg_format_file(void);
359359
static void arg_format_gcc(void);
360360
static void arg_format_groupnumber(void);
361+
static void arg_format_universalnumber(void);
361362
static void arg_format_limit(void);
362363
static void arg_format_producer(void);
363364
static void arg_format_snc(void);
@@ -596,6 +597,10 @@ static const char *usage_long_text[] = {
596597
"-u<file> --format-file=<file> Print only specified file (CU name)",
597598
"-x groupnumber=<n> ",
598599
" --format-group-number=<n> Groupnumber to print",
600+
"-x universalnumber=<n> ",
601+
" --format-universalnumber=<n> Groupnumber to print",
602+
" non-zero only applies to",
603+
" Mach-O universal binaries.",
599604
"-H<num> --format-limit=<num> Limit output to the first <num>",
600605
" major units.",
601606
" Stop after <num> compilation units",
@@ -739,11 +744,16 @@ OPT_FORMAT_SUPPRESS_URI, /* -U --format-suppress-uri */
739744
OPT_FORMAT_SUPPRESS_URI_MSG, /* -q --format-suppress-uri-msg */
740745

741746
OPT_FORMAT_SUPPRESS_UTF8, /* --format-suppress-utf8 */
747+
OPT_FORMAT_UNIVERSALNUMBER, /* --format-universalnumber */
742748

743749
/* Print Output Limiters */
744750
OPT_FORMAT_FILE, /* -u<file> --format-file=<file> */
745751
OPT_FORMAT_GCC, /* -cg --format-gcc */
746752
OPT_FORMAT_GROUP_NUMBER, /* -x<n> --format-group-number=<n>*/
753+
754+
/* -x<n> --format-universalnumber=<n>*/
755+
OPT_FORMAT_GROUP_UNIVERSALNUMBER,
756+
747757
OPT_FORMAT_LIMIT, /* -H<num> --format-limit=<num> */
748758
OPT_FORMAT_PRODUCER, /* -c<str> --format-producer=<str> */
749759
OPT_FORMAT_SNC, /* -cs --format-snc */
@@ -893,6 +903,8 @@ OPT_FORMAT_SUPPRESS_OFFSETS },
893903
{"format-gcc", dwno_argument, 0, OPT_FORMAT_GCC },
894904
{"format-group-number", dwrequired_argument, 0,
895905
OPT_FORMAT_GROUP_NUMBER},
906+
{"format-universalnumber", dwrequired_argument, 0,
907+
OPT_FORMAT_UNIVERSALNUMBER},
896908
{"format-limit", dwrequired_argument, 0, OPT_FORMAT_LIMIT },
897909
{"format-producer", dwrequired_argument, 0, OPT_FORMAT_PRODUCER},
898910
{"format-snc", dwno_argument, 0, OPT_FORMAT_SNC },
@@ -2148,6 +2160,9 @@ void arg_x_multiple_selection(void)
21482160
} else if (strncmp(dwoptarg,"groupnumber=",12) == 0) {
21492161
dwoptarg = &dwoptarg[12];
21502162
arg_format_groupnumber();
2163+
} else if (strncmp(dwoptarg,"universalnumber=",16) == 0) {
2164+
dwoptarg = &dwoptarg[12];
2165+
arg_format_universalnumber();
21512166
} else if (strncmp(dwoptarg,"tied=",5) == 0) {
21522167
dwoptarg = &dwoptarg[5];
21532168
arg_file_tied();
@@ -2187,6 +2202,32 @@ arg_file_abi(void)
21872202
}
21882203
}
21892204

2205+
/* Option '-x universalnumber='
2206+
greater than zero only applies to Mach-O universal
2207+
object files*/
2208+
static void
2209+
arg_format_universalnumber(void)
2210+
{
2211+
/* By default prints the lowest universal number in the object.
2212+
Default is -x universalnumber=0 */
2213+
2214+
long int gnum = 0;
2215+
int res = 0;
2216+
2217+
if (!dwoptarg || !dwoptarg[0]) {
2218+
printf("ERROR *groupnumber= does not allow an empty text\n");
2219+
glflags.gf_count_major_errors++;
2220+
arg_usage_error = TRUE;
2221+
return;
2222+
}
2223+
res = get_number_value(dwoptarg,&gnum);
2224+
if (res == DW_DLV_OK && gnum >= 0) {
2225+
glflags.gf_universalnumber = gnum;
2226+
} else {
2227+
arg_x_invalid();
2228+
}
2229+
}
2230+
21902231
/* Option '-x groupnumber=' */
21912232
static void
21922233
arg_format_groupnumber(void)
@@ -2510,6 +2551,8 @@ set_command_options(int argc, char *argv[])
25102551
case OPT_FORMAT_FILE: arg_format_file(); break;
25112552
case OPT_FORMAT_GCC: arg_format_gcc(); break;
25122553
case OPT_FORMAT_GROUP_NUMBER: arg_format_groupnumber(); break;
2554+
case OPT_FORMAT_UNIVERSALNUMBER: arg_format_universalnumber();
2555+
break;
25132556
case OPT_FORMAT_LIMIT: arg_format_limit(); break;
25142557
case OPT_FORMAT_PRODUCER: arg_format_producer(); break;
25152558
case OPT_FORMAT_SNC: arg_format_snc(); break;

src/bin/dwarfdump/dd_glflags.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ init_global_flags(void)
316316
/* Output filename */
317317
glflags.output_file = 0;
318318
glflags.group_number = 0;
319+
glflags.gf_universalnumber = 0;/* for Mach-O universal binaries */
319320

320321
/* Global esb-buffers. */
321322
glflags.newprogname = &_newprogname;

src/bin/dwarfdump/dd_glflags.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ struct glflags_s {
378378

379379
/* Output filename */
380380
const char *output_file;
381-
int group_number;
381+
int group_number;
382+
unsigned gf_universalnumber; /* for Mach-O universal binaries*/
382383

383384
/* Global esb-buffers. */
384385
struct esb_s *newprogname;

src/bin/dwarfdump/dwarfdump.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ main(int argc, char *argv[])
561561
glflags.gf_count_major_errors++;
562562
} else if (ftype == DW_FTYPE_ELF ||
563563
ftype == DW_FTYPE_MACH_O ||
564+
ftype == DW_FTYPE_APPLEUNIVERSAL ||
564565
ftype == DW_FTYPE_PE ) {
565566
flag_data_pre_allocation();
566567
close_a_file(global_basefd);
@@ -913,9 +914,10 @@ process_one_file(
913914
tb = 0;
914915
tblen = 0;
915916
}
916-
dres = dwarf_init_path_dl(file_name,
917+
dres = dwarf_init_path_dl_a(file_name,
917918
tb,tblen,
918919
glflags.group_number,
920+
glflags.gf_universalnumber,
919921
NULL, NULL, &dbg,
920922
glflags.gf_global_debuglink_paths,
921923
glflags.gf_global_debuglink_count,
@@ -951,10 +953,11 @@ process_one_file(
951953
{
952954
/* The tied file we define as group 1, BASE.
953955
Cannot follow debuglink or dSYM,
954-
is a tied file */
955-
dres = dwarf_init_path(tied_file_name,
956+
is a tied file */
957+
dres = dwarf_init_path_a(tied_file_name,
956958
0,0, /* ignore dSYM & debuglink */
957959
DW_GROUPNUMBER_BASE,
960+
glflags.gf_universalnumber,
958961
0,0,
959962
&dbgtied,
960963
&onef_err);

0 commit comments

Comments
 (0)