📄 gdbint.texinfo
字号:
@cindex item output functions@cindex field output functions@cindex data outputThe functions described below produce output for the actual dataitems, or fields, which contain information about the object.Choose the appropriate function accordingly to your particular needs.@deftypefun void ui_out_field_fmt (struct ui_out *@var{uiout}, char *@var{fldname}, char *@var{format}, ...)This is the most general output function. It produces therepresentation of the data in the variable-length argument listaccording to formatting specifications in @var{format}, a@code{printf}-like format string. The optional argument @var{fldname}supplies the name of the field. The data items themselves aresupplied as additional arguments after @var{format}.This generic function should be used only when it is not possible touse one of the specialized versions (see below).@end deftypefun@deftypefun void ui_out_field_int (struct ui_out *@var{uiout}, const char *@var{fldname}, int @var{value})This function outputs a value of an @code{int} variable. It uses the@code{"%d"} output conversion specification. @var{fldname} specifiesthe name of the field.@end deftypefun@deftypefun void ui_out_field_fmt_int (struct ui_out *@var{uiout}, int @var{width}, enum ui_align @var{alignment}, const char *@var{fldname}, int @var{value})This function outputs a value of an @code{int} variable. It differs from@code{ui_out_field_int} in that the caller specifies the desired @var{width} and @var{alignment} of the output.@var{fldname} specifiesthe name of the field.@end deftypefun@deftypefun void ui_out_field_core_addr (struct ui_out *@var{uiout}, const char *@var{fldname}, CORE_ADDR @var{address})This function outputs an address.@end deftypefun@deftypefun void ui_out_field_string (struct ui_out *@var{uiout}, const char *@var{fldname}, const char *@var{string})This function outputs a string using the @code{"%s"} conversionspecification.@end deftypefunSometimes, there's a need to compose your output piece by piece usingfunctions that operate on a stream, such as @code{value_print} or@code{fprintf_symbol_filtered}. These functions accept an argument ofthe type @code{struct ui_file *}, a pointer to a @code{ui_file} objectused to store the data stream used for the output. When you use oneof these functions, you need a way to pass their results stored in a@code{ui_file} object to the @code{ui_out} functions. To this end,you first create a @code{ui_stream} object by calling@code{ui_out_stream_new}, pass the @code{stream} member of that@code{ui_stream} object to @code{value_print} and similar functions,and finally call @code{ui_out_field_stream} to output the field youconstructed. When the @code{ui_stream} object is no longer needed,you should destroy it and free its memory by calling@code{ui_out_stream_delete}.@deftypefun struct ui_stream *ui_out_stream_new (struct ui_out *@var{uiout})This function creates a new @code{ui_stream} object which uses thesame output methods as the @code{ui_out} object whose pointer ispassed in @var{uiout}. It returns a pointer to the newly created@code{ui_stream} object.@end deftypefun@deftypefun void ui_out_stream_delete (struct ui_stream *@var{streambuf})This functions destroys a @code{ui_stream} object specified by@var{streambuf}.@end deftypefun@deftypefun void ui_out_field_stream (struct ui_out *@var{uiout}, const char *@var{fieldname}, struct ui_stream *@var{streambuf})This function consumes all the data accumulated in@code{streambuf->stream} and outputs it like@code{ui_out_field_string} does. After a call to@code{ui_out_field_stream}, the accumulated data no longer exists, butthe stream is still valid and may be used for producing more fields.@end deftypefun@strong{Important:} If there is any chance that your code could bailout before completing output generation and reaching the point where@code{ui_out_stream_delete} is called, it is necessary to set up acleanup, to avoid leaking memory and other resources. Here's askeleton code to do that:@smallexample struct ui_stream *mybuf = ui_out_stream_new (uiout); struct cleanup *old = make_cleanup (ui_out_stream_delete, mybuf); ... do_cleanups (old);@end smallexampleIf the function already has the old cleanup chain set (for other kindsof cleanups), you just have to add your cleanup to it:@smallexample mybuf = ui_out_stream_new (uiout); make_cleanup (ui_out_stream_delete, mybuf);@end smallexampleNote that with cleanups in place, you should not call@code{ui_out_stream_delete} directly, or you would attempt to free thesame buffer twice.@subsection Utility Output Functions@deftypefun void ui_out_field_skip (struct ui_out *@var{uiout}, const char *@var{fldname})This function skips a field in a table. Use it if you have to leavean empty field without disrupting the table alignment. The argument@var{fldname} specifies a name for the (missing) filed.@end deftypefun@deftypefun void ui_out_text (struct ui_out *@var{uiout}, const char *@var{string})This function outputs the text in @var{string} in a way that makes iteasy to be read by humans. For example, the console implementation ofthis method filters the text through a built-in pager, to prevent itfrom scrolling off the visible portion of the screen.Use this function for printing relatively long chunks of text aroundthe actual field data: the text it produces is not aligned accordingto the table's format. Use @code{ui_out_field_string} to output astring field, and use @code{ui_out_message}, described below, tooutput short messages.@end deftypefun@deftypefun void ui_out_spaces (struct ui_out *@var{uiout}, int @var{nspaces})This function outputs @var{nspaces} spaces. It is handy to align thetext produced by @code{ui_out_text} with the rest of the table orlist.@end deftypefun@deftypefun void ui_out_message (struct ui_out *@var{uiout}, int @var{verbosity}, const char *@var{format}, ...)This function produces a formatted message, provided that the currentverbosity level is at least as large as given by @var{verbosity}. Thecurrent verbosity level is specified by the user with the @samp{setverbositylevel} command.@footnote{As of this writing (April 2001),setting verbosity level is not yet implemented, and is always returnedas zero. So calling @code{ui_out_message} with a @var{verbosity}argument more than zero will cause the message to never be printed.}@end deftypefun@deftypefun void ui_out_wrap_hint (struct ui_out *@var{uiout}, char *@var{indent})This function gives the console output filter (a paging filter) a hintof where to break lines which are too long. Ignored for all otheroutput consumers. @var{indent}, if non-@code{NULL}, is the string tobe printed to indent the wrapped text on the next line; it must remainaccessible until the next call to @code{ui_out_wrap_hint}, or until anexplicit newline is produced by one of the other functions. If@var{indent} is @code{NULL}, the wrapped text will not be indented.@end deftypefun@deftypefun void ui_out_flush (struct ui_out *@var{uiout})This function flushes whatever output has been accumulated so far, ifthe UI buffers output.@end deftypefun@subsection Examples of Use of @code{ui_out} functions@cindex using @code{ui_out} functions@cindex @code{ui_out} functions, usage examplesThis section gives some practical examples of using the @code{ui_out}functions to generalize the old console-oriented code in@value{GDBN}. The examples all come from functions defined on the@file{breakpoints.c} file.This example, from the @code{breakpoint_1} function, shows how toproduce a table.The original code was:@smallexample if (!found_a_breakpoint++) @{ annotate_breakpoints_headers (); annotate_field (0); printf_filtered ("Num "); annotate_field (1); printf_filtered ("Type "); annotate_field (2); printf_filtered ("Disp "); annotate_field (3); printf_filtered ("Enb "); if (addressprint) @{ annotate_field (4); printf_filtered ("Address "); @} annotate_field (5); printf_filtered ("What\n"); annotate_breakpoints_table (); @}@end smallexampleHere's the new version:@smallexample nr_printable_breakpoints = @dots{}; if (addressprint) ui_out_table_begin (ui, 6, nr_printable_breakpoints, "BreakpointTable"); else ui_out_table_begin (ui, 5, nr_printable_breakpoints, "BreakpointTable"); if (nr_printable_breakpoints > 0) annotate_breakpoints_headers (); if (nr_printable_breakpoints > 0) annotate_field (0); ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */ if (nr_printable_breakpoints > 0) annotate_field (1); ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ if (nr_printable_breakpoints > 0) annotate_field (2); ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ if (nr_printable_breakpoints > 0) annotate_field (3); ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ if (addressprint) @{ if (nr_printable_breakpoints > 0) annotate_field (4); if (TARGET_ADDR_BIT <= 32) ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ else ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ @} if (nr_printable_breakpoints > 0) annotate_field (5); ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ ui_out_table_body (uiout); if (nr_printable_breakpoints > 0) annotate_breakpoints_table ();@end smallexampleThis example, from the @code{print_one_breakpoint} function, shows howto produce the actual data for the table whose structure was definedin the above example. The original code was:@smallexample annotate_record (); annotate_field (0); printf_filtered ("%-3d ", b->number); annotate_field (1); if ((int)b->type > (sizeof(bptypes)/sizeof(bptypes[0])) || ((int) b->type != bptypes[(int) b->type].type)) internal_error ("bptypes table does not describe type #%d.", (int)b->type); printf_filtered ("%-14s ", bptypes[(int)b->type].description); annotate_field (2); printf_filtered ("%-4s ", bpdisps[(int)b->disposition]); annotate_field (3); printf_filtered ("%-3c ", bpenables[(int)b->enable]); @dots{}@end smallexampleThis is the new version:@smallexample annotate_record (); ui_out_tuple_begin (uiout, "bkpt"); annotate_field (0); ui_out_field_int (uiout, "number", b->number); annotate_field (1); if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0]))) || ((int) b->type != bptypes[(int) b->type].type)) internal_error ("bptypes table does not describe type #%d.", (int) b->type); ui_out_field_string (uiout, "type", bptypes[(int)b->type].description); annotate_field (2); ui_out_field_string (uiout, "disp", bpdisps[(int)b->disposition]); annotate_field (3); ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int)b->enable]); @dots{}@end smallexampleThis example, also from @code{print_one_breakpoint}, shows how toproduce a complicated output field using the @code{print_expression}functions which requires a stream to be passed. It also shows how toautomate stream destruction with cleanups. The original code was:@smallexample annotate_field (5); print_expression (b->exp, gdb_stdout);@end smallexampleThe new version is:@smallexample struct ui_stream *stb = ui_out_stream_new (uiout); struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); ... annotate_field (5); print_expression (b->exp, stb->stream); ui_out_field_stream (uiout, "what", local_stream);@end smallexampleThis example, also from @code{print_one_breakpoint}, shows how to use@code{ui_out_text} and @code{ui_out_field_string}. The original codewas:@smallexample annotate_field (5); if (b->dll_pathname == NULL) printf_filtered ("<any library> "); else printf_filtered ("library \"%s\" ", b->dll_pathname);@end smallexampleIt became:@smallexample annotate_field (5); if (b->dll_pathname == NULL) @{ ui_out_field_string (uiout, "what", "<any library>"); ui_out_spaces (uiout, 1); @} else @{ ui_out_text (uiout, "library \""); ui_out_field_string (uiout, "what", b->dll_pathname); ui_out_text (uiout, "\" "); @}@end smallexampleThe following example from @code{print_one_breakpoint} shows how touse @code{ui_out_field_int} and @code{ui_out_spaces}. The originalcode was:@smallexample annotate_field (5); if (b->forked_inferior_pid != 0) printf_filtered ("process %d ", b->forked_inferior_pid);@end smallexample
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -