GNU Binutils with patches for OS216
修訂 | 43436142530dc00cee6f3f7379bd1c2694ef2e14 (tree) |
---|---|
時間 | 2019-07-02 04:15:58 |
作者 | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
Introduce string_field
For ... string fields.
@@ -6193,10 +6193,9 @@ print_one_breakpoint_location (struct breakpoint *b, | ||
6193 | 6193 | && breakpoint_condition_evaluation_mode () |
6194 | 6194 | == condition_evaluation_target) |
6195 | 6195 | { |
6196 | - uiout->text (" ("); | |
6197 | - uiout->field_string ("evaluated-by", | |
6198 | - bp_condition_evaluator (b)); | |
6199 | - uiout->text (" evals)"); | |
6196 | + uiout->message (" (%pF evals)", | |
6197 | + string_field ("evaluated-by", | |
6198 | + bp_condition_evaluator (b))); | |
6200 | 6199 | } |
6201 | 6200 | uiout->text ("\n"); |
6202 | 6201 | } |
@@ -12752,10 +12751,9 @@ tracepoint_print_one_detail (const struct breakpoint *self, | ||
12752 | 12751 | { |
12753 | 12752 | gdb_assert (self->type == bp_static_tracepoint); |
12754 | 12753 | |
12755 | - uiout->text ("\tmarker id is "); | |
12756 | - uiout->field_string ("static-tracepoint-marker-string-id", | |
12757 | - tp->static_trace_marker_id); | |
12758 | - uiout->text ("\n"); | |
12754 | + uiout->message ("\tmarker id is %pF\n", | |
12755 | + string_field ("static-tracepoint-marker-string-id", | |
12756 | + tp->static_trace_marker_id.c_str ())); | |
12759 | 12757 | } |
12760 | 12758 | } |
12761 | 12759 |
@@ -7641,24 +7641,19 @@ print_exited_reason (struct ui_out *uiout, int exitstatus) | ||
7641 | 7641 | { |
7642 | 7642 | if (uiout->is_mi_like_p ()) |
7643 | 7643 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED)); |
7644 | - uiout->text ("[Inferior "); | |
7645 | - uiout->text (plongest (inf->num)); | |
7646 | - uiout->text (" ("); | |
7647 | - uiout->text (pidstr.c_str ()); | |
7648 | - uiout->text (") exited with code "); | |
7649 | - uiout->field_fmt ("exit-code", "0%o", (unsigned int) exitstatus); | |
7650 | - uiout->text ("]\n"); | |
7644 | + std::string exit_code_str | |
7645 | + = string_printf ("0%o", (unsigned int) exitstatus); | |
7646 | + uiout->message ("[Inferior %s (%s) exited with code %pF]\n", | |
7647 | + plongest (inf->num), pidstr.c_str (), | |
7648 | + string_field ("exit-code", exit_code_str.c_str ())); | |
7651 | 7649 | } |
7652 | 7650 | else |
7653 | 7651 | { |
7654 | 7652 | if (uiout->is_mi_like_p ()) |
7655 | 7653 | uiout->field_string |
7656 | 7654 | ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); |
7657 | - uiout->text ("[Inferior "); | |
7658 | - uiout->text (plongest (inf->num)); | |
7659 | - uiout->text (" ("); | |
7660 | - uiout->text (pidstr.c_str ()); | |
7661 | - uiout->text (") exited normally]\n"); | |
7655 | + uiout->message ("[Inferior %s (%s) exited normally]\n", | |
7656 | + plongest (inf->num), pidstr.c_str ()); | |
7662 | 7657 | } |
7663 | 7658 | } |
7664 | 7659 |
@@ -607,8 +607,22 @@ ui_out::vmessage (const char *format, va_list args) | ||
607 | 607 | { |
608 | 608 | case 'F': |
609 | 609 | { |
610 | - int_field_s *field = va_arg (args, int_field_s *); | |
611 | - field_int (field->name, field->val); | |
610 | + base_field_s *bf = va_arg (args, base_field_s *); | |
611 | + switch (bf->kind) | |
612 | + { | |
613 | + case field_kind::INT: | |
614 | + { | |
615 | + auto *f = (int_field_s *) bf; | |
616 | + field_int (f->name, f->val); | |
617 | + } | |
618 | + break; | |
619 | + case field_kind::STRING: | |
620 | + { | |
621 | + auto *f = (string_field_s *) bf; | |
622 | + field_string (f->name, f->str); | |
623 | + } | |
624 | + break; | |
625 | + } | |
612 | 626 | } |
613 | 627 | break; |
614 | 628 | case 's': |
@@ -68,11 +68,25 @@ enum ui_out_type | ||
68 | 68 | ui_out_type_list |
69 | 69 | }; |
70 | 70 | |
71 | +/* The possible kinds of fields. */ | |
72 | +enum class field_kind | |
73 | + { | |
74 | + INT, | |
75 | + STRING, | |
76 | + }; | |
77 | + | |
71 | 78 | /* An int field, to be passed to %pF in format strings. */ |
72 | 79 | |
73 | -struct int_field_s | |
80 | +struct base_field_s | |
74 | 81 | { |
75 | 82 | const char *name; |
83 | + field_kind kind; | |
84 | +}; | |
85 | + | |
86 | +/* An int field, to be passed to %pF in format strings. */ | |
87 | + | |
88 | +struct int_field_s : base_field_s | |
89 | +{ | |
76 | 90 | int val; |
77 | 91 | }; |
78 | 92 |
@@ -85,10 +99,32 @@ int_field (const char *name, int val, | ||
85 | 99 | int_field_s &&tmp = {}) |
86 | 100 | { |
87 | 101 | tmp.name = name; |
102 | + tmp.kind = field_kind::INT; | |
88 | 103 | tmp.val = val; |
89 | 104 | return &tmp; |
90 | 105 | } |
91 | 106 | |
107 | +/* A string field, to be passed to %pF in format strings. */ | |
108 | + | |
109 | +struct string_field_s : base_field_s | |
110 | +{ | |
111 | + const char *str; | |
112 | +}; | |
113 | + | |
114 | +/* Construct a temporary string_field_s on the caller's stack and | |
115 | + return a pointer to the constructed object. We use this because | |
116 | + it's not possible to pass a reference via va_args. */ | |
117 | + | |
118 | +static inline string_field_s * | |
119 | +string_field (const char *name, const char *str, | |
120 | + string_field_s &&tmp = {}) | |
121 | +{ | |
122 | + tmp.name = name; | |
123 | + tmp.kind = field_kind::STRING; | |
124 | + tmp.str = str; | |
125 | + return &tmp; | |
126 | +} | |
127 | + | |
92 | 128 | /* A styled string. */ |
93 | 129 | |
94 | 130 | struct styled_string_s |