GDB (API)
/home/stan/gdb/src/gdb/utils.h
Go to the documentation of this file.
00001 /* *INDENT-OFF* */ /* ATTRIBUTE_PRINTF confuses indent, avoid running it
00002                       for now.  */
00003 /* I/O, string, cleanup, and other random utilities for GDB.
00004    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00005 
00006    This file is part of GDB.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 #ifndef UTILS_H
00022 #define UTILS_H
00023 
00024 #include "cleanups.h"
00025 #include "exceptions.h"
00026 
00027 extern void initialize_utils (void);
00028 
00029 /* String utilities.  */
00030 
00031 extern int sevenbit_strings;
00032 
00041 extern char *savestring (const char *ptr, size_t len);
00042 
00043 extern int strcmp_iw (const char *, const char *);
00044 
00083 extern int strcmp_iw_ordered (const char *string1, const char *string2);
00084 
00087 extern int streq (const char *lhs, const char *rhs);
00088 
00094 extern int subset_compare (char *string_to_compare, char *template_string);
00095 
00098 ULONGEST strtoulst (const char *num, const char **trailer, int base);
00099 
00102 int compare_positive_ints (const void *ap, const void *bp);
00103 
00106 int compare_strings (const void *ap, const void *bp);
00107 
00113 extern char *safe_strerror (int);
00114 
00123 extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **matching);
00124 
00125 /* Reset the prompt_for_continue clock.  */
00126 void reset_prompt_for_continue_wait_time (void);
00127 /* Return the time spent in prompt_for_continue.  */
00128 struct timeval get_prompt_for_continue_wait_time (void);
00129 
00130 /* Parsing utilites.  */
00131 
00134 extern int parse_pid_to_attach (char *args);
00135 
00152 extern int parse_escape (struct gdbarch *, const char **);
00153 
00160 char **gdb_buildargv (const char *s);
00161 
00162 /* Cleanup utilities.  */
00163 
00164 extern struct cleanup *make_cleanup_freeargv (char **);
00165 
00166 struct dyn_string;
00167 extern struct cleanup *make_cleanup_dyn_string_delete (struct dyn_string *);
00168 
00169 struct ui_file;
00170 extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *);
00171 
00172 struct ui_out;
00173 extern struct cleanup *
00174   make_cleanup_ui_out_redirect_pop (struct ui_out *uiout);
00175 
00176 struct section_addr_info;
00177 extern struct cleanup *(make_cleanup_free_section_addr_info 
00178                         (struct section_addr_info *));
00179 
00180 extern struct cleanup *make_cleanup_close (int fd);
00181 
00182 extern struct cleanup *make_cleanup_fclose (FILE *file);
00183 
00184 extern struct cleanup *make_cleanup_bfd_unref (bfd *abfd);
00185 
00186 struct obstack;
00187 extern struct cleanup *make_cleanup_obstack_free (struct obstack *obstack);
00188 
00189 extern struct cleanup *make_cleanup_restore_integer (int *variable);
00190 extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable);
00191 
00192 struct target_ops;
00193 extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops);
00194 
00195 extern struct cleanup *
00196   make_cleanup_restore_ui_file (struct ui_file **variable);
00197 
00198 extern struct cleanup *make_cleanup_value_free_to_mark (struct value *);
00199 extern struct cleanup *make_cleanup_value_free (struct value *);
00200 
00201 struct so_list;
00202 extern struct cleanup *make_cleanup_free_so (struct so_list *so);
00203 
00204 extern struct cleanup *make_cleanup_restore_current_language (void);
00205 
00206 extern struct cleanup *make_cleanup_htab_delete (htab_t htab);
00207 
00208 extern void free_current_contents (void *);
00209 
00210 extern void init_page_info (void);
00211 
00212 extern struct cleanup *make_cleanup_restore_page_info (void);
00213 extern struct cleanup *
00214   set_batch_flag_and_make_cleanup_restore_page_info (void);
00215 
00216 extern struct cleanup *make_bpstat_clear_actions_cleanup (void);
00217 
00218 /* Path utilities.  */
00219 
00226 extern char *gdb_realpath (const char *filename);
00227 
00228 extern int gdb_filename_fnmatch (const char *pattern, const char *string,
00229                                  int flags);
00230 
00231 extern void substitute_path_component (char **stringp, const char *from,
00232                                        const char *to);
00233 
00234 char *ldirname (const char *filename);
00235 
00236 /* GDB output, ui_file utilities.  */
00237 
00238 struct ui_file;
00239 
00240 extern int query (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
00241 extern int nquery (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
00242 extern int yquery (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
00243 
00244 extern void begin_line (void);
00245 
00246 extern void wrap_here (char *);
00247 
00248 extern void reinitialize_more_filter (void);
00249 
00250 extern int pagination_enabled;
00251 
00252 /* Global ui_file streams.  These are all defined in main.c.  */
00253 
00255 extern struct ui_file *gdb_stdout;
00257 extern struct ui_file *gdb_stdin;
00259 extern struct ui_file *gdb_stderr;
00265 extern struct ui_file *gdb_stdlog;
00271 extern struct ui_file *gdb_stdtarg;
00272 extern struct ui_file *gdb_stdtargerr;
00273 extern struct ui_file *gdb_stdtargin;
00274 
00275 /* More generic printf like operations.  Filtered versions may return
00276    non-locally on error.  */
00277 
00280 extern void fputs_filtered (const char *, struct ui_file *);
00281 
00284 extern void fputs_unfiltered (const char *, struct ui_file *);
00285 
00288 extern int fputc_filtered (int c, struct ui_file *);
00289 
00292 extern int fputc_unfiltered (int c, struct ui_file *);
00293 
00296 extern int putchar_filtered (int c);
00297 
00300 extern int putchar_unfiltered (int c);
00301 
00304 extern void puts_filtered (const char *);
00305 
00308 extern void puts_unfiltered (const char *);
00309 
00317 extern void puts_filtered_tabular (char *string, int width, int right);
00318 
00323 extern void puts_debug (char *prefix, char *string, char *suffix);
00324 
00325 extern void vprintf_filtered (const char *, va_list) ATTRIBUTE_PRINTF (1, 0);
00326 
00327 extern void vfprintf_filtered (struct ui_file *, const char *, va_list)
00328   ATTRIBUTE_PRINTF (2, 0);
00329 
00330 extern void fprintf_filtered (struct ui_file *, const char *, ...)
00331   ATTRIBUTE_PRINTF (2, 3);
00332 
00333 extern void fprintfi_filtered (int, struct ui_file *, const char *, ...)
00334   ATTRIBUTE_PRINTF (3, 4);
00335 
00336 extern void printf_filtered (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
00337 
00338 extern void printfi_filtered (int, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
00339 
00340 extern void vprintf_unfiltered (const char *, va_list) ATTRIBUTE_PRINTF (1, 0);
00341 
00342 extern void vfprintf_unfiltered (struct ui_file *, const char *, va_list)
00343   ATTRIBUTE_PRINTF (2, 0);
00344 
00345 extern void fprintf_unfiltered (struct ui_file *, const char *, ...)
00346   ATTRIBUTE_PRINTF (2, 3);
00347 
00348 extern void printf_unfiltered (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
00349 
00350 extern void print_spaces (int, struct ui_file *);
00351 
00352 extern void print_spaces_filtered (int, struct ui_file *);
00353 
00354 extern char *n_spaces (int);
00355 
00356 extern void fputstr_filtered (const char *str, int quotr,
00357                               struct ui_file * stream);
00358 
00359 extern void fputstr_unfiltered (const char *str, int quotr,
00360                                 struct ui_file * stream);
00361 
00362 extern void fputstrn_filtered (const char *str, int n, int quotr,
00363                                struct ui_file * stream);
00364 
00365 extern void fputstrn_unfiltered (const char *str, int n, int quotr,
00366                                  struct ui_file * stream);
00367 
00369 extern void gdb_print_host_address (const void *addr, struct ui_file *stream);
00370 
00371 extern const char *host_address_to_string (const void *addr);
00372 
00377 extern const char *paddress (struct gdbarch *gdbarch, CORE_ADDR addr);
00378 
00383 extern const char *print_core_address (struct gdbarch *gdbarch,
00384                                        CORE_ADDR address);
00385 
00386 /* Callback hash_f and eq_f for htab_create_alloc or htab_create_alloc_ex.  */
00387 extern hashval_t core_addr_hash (const void *ap);
00388 extern int core_addr_eq (const void *ap, const void *bp);
00389 
00395 extern char *plongest (LONGEST l);
00396 
00402 extern char *pulongest (ULONGEST l);
00403 
00412 extern char *phex (ULONGEST l, int sizeof_l);
00413 
00422 extern char *phex_nz (ULONGEST l, int sizeof_l);
00423 
00432 extern char *int_string (LONGEST val, int radix, int is_signed, int width, 
00433                          int use_c_format);
00434 
00441 extern const char *core_addr_to_string (const CORE_ADDR addr);
00442 
00449 extern const char *core_addr_to_string_nz (const CORE_ADDR addr);
00450 
00456 extern CORE_ADDR string_to_core_addr (const char *my_string);
00457 
00462 extern char *hex_string (LONGEST);
00463 
00464 extern char *hex_string_custom (LONGEST, int);
00465 
00466 extern void fprintf_symbol_filtered (struct ui_file *, const char *,
00467                                      enum language, int);
00468 
00469 extern void throw_perror_with_name (enum errors errcode, const char *string)
00470   ATTRIBUTE_NORETURN;
00471 extern void perror_with_name (const char *) ATTRIBUTE_NORETURN;
00472 
00473 extern void perror_warning_with_name (const char *string);
00474 
00475 extern void print_sys_errmsg (const char *, int);
00476 
00477 /* Warnings and error messages.  */
00478 
00479 extern void (*deprecated_error_begin_hook) (void);
00480 
00485 extern char *warning_pre_print;
00486 
00487 extern void verror (const char *fmt, va_list ap)
00488      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 0);
00489 
00490 extern void error (const char *fmt, ...)
00491      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
00492 
00493 extern void error_stream (struct ui_file *) ATTRIBUTE_NORETURN;
00494 
00495 extern void vfatal (const char *fmt, va_list ap)
00496      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 0);
00497 
00498 extern void fatal (const char *fmt, ...)
00499      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
00500 
00501 extern void internal_verror (const char *file, int line, const char *,
00502                              va_list ap)
00503      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0);
00504 
00505 extern void internal_vwarning (const char *file, int line,
00506                                const char *, va_list ap)
00507      ATTRIBUTE_PRINTF (3, 0);
00508 
00509 extern void internal_warning (const char *file, int line,
00510                               const char *, ...) ATTRIBUTE_PRINTF (3, 4);
00511 
00520 extern void warning (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
00521 
00524 extern void vwarning (const char *, va_list args) ATTRIBUTE_PRINTF (1, 0);
00525 
00526 /* Misc. utilities.  */
00527 
00528 /* Allocation and deallocation functions for the libiberty hash table
00529    which use obstacks.  */
00530 void *hashtab_obstack_allocate (void *data, size_t size, size_t count);
00531 void dummy_obstack_deallocate (void *object, void *data);
00532 
00533 #ifdef HAVE_WAITPID
00534 extern pid_t wait_to_die_with_timeout (pid_t pid, int *status, int timeout);
00535 #endif
00536 
00543 extern int producer_is_gcc_ge_4 (const char *producer);
00544 
00545 extern int myread (int, char *, int);
00546 
00547 /* Ensure that V is aligned to an N byte boundary (B's assumed to be a
00548    power of 2).  Round up/down when necessary.  Examples of correct
00549    use include:
00550 
00551    addr = align_up (addr, 8); -- VALUE needs 8 byte alignment
00552    write_memory (addr, value, len);
00553    addr += len;
00554 
00555    and:
00556 
00557    sp = align_down (sp - len, 16); -- Keep SP 16 byte aligned
00558    write_memory (sp, value, len);
00559 
00560    Note that uses such as:
00561 
00562    write_memory (addr, value, len);
00563    addr += align_up (len, 8);
00564 
00565    and:
00566 
00567    sp -= align_up (len, 8);
00568    write_memory (sp, value, len);
00569 
00570    are typically not correct as they don't ensure that the address (SP
00571    or ADDR) is correctly aligned (relying on previous alignment to
00572    keep things right).  This is also why the methods are called
00573    "align_..." instead of "round_..." as the latter reads better with
00574    this incorrect coding style.  */
00575 
00576 extern ULONGEST align_up (ULONGEST v, int n);
00577 extern ULONGEST align_down (ULONGEST v, int n);
00578 
00579 /* Sign extend VALUE.  BIT is the (1-based) index of the bit in VALUE
00580    to sign-extend.  */
00581 
00582 extern LONGEST gdb_sign_extend (LONGEST value, int bit);
00583 
00584 #endif /* UTILS_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines