aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
AgeCommit message (Collapse)AuthorFilesLines
2017-10-31Use console uiout when executing breakpoint commandsSimon Marchi1-4/+18
As reported here https://sourceware.org/ml/gdb/2017-10/msg00020.html the output of certain commands, like backtrace, doesn't appear anywhere when it is run as a breakpoint command and when using MI. The reason is that the current_uiout is set to the mi_ui_out while these commands run, whereas we want the output as CLI output. Some commands like "print" work, because they use printf_filtered (gdb_stdout, ...) directly, bypassing the current ui_out. The fix I did is to force setting the cli_uiout as the current_uiout when calling execute_control_command. I am not sure if this is the right way to fix the problem, comments about the approach would be appreciated. I enhanced gdb.mi/mi-break.exp to test the backtrace command. Regtested on the buildbot. gdb/ChangeLog: * cli/cli-script.c (execute_control_command): Rename to ... (execute_control_command_1): ... this. (execute_control_command): New function. gdb/testsuite/ChangeLog: * gdb.mi/mi-break.exp (test_breakpoint_commands): Test backtrace as a breakpoint command.
2017-10-11Constify add_prefix_cmdTom Tromey4-22/+23
This changes add_prefix_cmd to accept a const-taking function as an argument; then fixes up all the callers. In a couple of spots I had to add a non-const overload of a function, because the function is passed to two different command-adding "constructors". These overloads are temporary; once constification is complete they can be removed. This patch also fixes a typo I happened to notice while constifying. Note that this touches a couple of files (gnu-nat.c and go32-nat.c) that I can't build. So, while I made a best-effort there, I am not certain they will still compile. Tested by rebuilding. gdb/ChangeLog 2017-10-11 Tom Tromey <tom@tromey.com> * gdbthread.h (thread_command): Constify. * inferior.h (detach_command): Constify. * top.h (set_history, show_history): Constify. * arm-tdep.c (set_arm_command, show_arm_command): Constify. * serial.c (serial_set_cmd, serial_show_cmd): Constify. * bsd-kvm.c (bsd_kvm_cmd): Constify. * printcmd.c (set_command): Constify. (non_const_set_command): New function. * dcache.c (set_dcache_command, show_dcache_command): Constify. * breakpoint.c (enable_command, disable_command, delete_command) (catch_command, tcatch_command, set_breakpoint_cmd) (show_breakpoint_cmd): Constify. * macrocmd.c (macro_command): Constify. * infcmd.c (unset_command, kill_command, detach_command) (info_proc_cmd): Constify. * i386-tdep.c (set_mpx_cmd, show_mpx_cmd): Constify. * auto-load.c (show_auto_load_cmd, set_auto_load_cmd) (info_auto_load_cmd): Constify. * target-descriptions.c (set_tdesc_cmd, show_tdesc_cmd) (unset_tdesc_cmd): Constify. * ada-lang.c (set_ada_command, show_ada_command) (maint_set_ada_cmd, maint_show_ada_cmd): Constify. * guile/guile.c (set_guile_command, show_guile_command) (info_guile_command): Constify. * tui/tui-win.c (tui_command, set_tui_cmd, show_tui_cmd): Constify. * skip.c (skip_command): Constify. * compile/compile.c (_initialize_compile): Constify. * dwarf2read.c (set_dwarf_cmd, show_dwarf_cmd): Constify. * btrace.c (maint_btrace_cmd, maint_btrace_set_cmd) (maint_btrace_show_cmd, maint_btrace_pt_set_cmd) (maint_btrace_pt_show_cmd): Constify. * remote.c (set_remote_cmd, show_remote_cmd, remote_command): Constify. * python/python.c (user_show_python, user_set_python): Constify. * mips-tdep.c (set_mips_command, show_mips_command) (set_mipsfpu_command): Constify. * record-btrace.c (cmd_record_btrace_start) (cmd_set_record_btrace, cmd_show_record_btrace) (cmd_set_record_btrace_bts, cmd_show_record_btrace_bts) (cmd_set_record_btrace_pt, cmd_show_record_btrace_pt): Constify. * rs6000-tdep.c (set_powerpc_command, show_powerpc_command): Constify. * symfile.c (overlay_command): Constify. * spu-tdep.c (set_spu_command, show_spu_command): Constify. * cli/cli-logging.c (set_logging_command, show_logging_command): Constify. * cli/cli-dump.c (dump_command, append_command) (srec_dump_command, ihex_dump_command, verilog_dump_command) (tekhex_dump_command, binary_dump_command) (binary_append_command): Constify. * cli/cli-decode.c (struct cmd_list_element): Change type of "fun". * cli/cli-cmds.c (info_command, show_command, set_debug) (show_debug): Constify. (show_command): Add non-const overload. * top.c (set_history, show_history): Constify. * sh-tdep.c (set_sh_command, show_sh_command): Constify. * command.h (add_prefix_cmd): Accept a cmd_const_cfunc_ftype. * target.c (target_command): Constify. * sparc64-tdep.c (info_adi_command): Constify. * record-full.c (cmd_record_full_start): Constify. (set_record_full_command): Constify. Fix typo. (show_record_full_command): Constify. * thread.c (thread_command, thread_apply_command): Constify. * memattr.c (dummy_cmd): Constify. * value.c (function_command): Constify. * frame.c (set_backtrace_cmd, show_backtrace_cmd): Constify. * probe.c (info_probes_command): Constify. * ser-tcp.c (set_tcp_cmd, show_tcp_cmd): Constify. * gnu-nat.c (set_task_cmd, show_task_cmd, set_thread_cmd) (show_thread_cmd, set_thread_default_cmd) (show_thread_default_cmd): Constify. (check_empty): Constify. * tracepoint.c (tfind_command): Constify. * cp-support.c (maint_cplus_command): Constify. * windows-tdep.c (info_w32_command): Constify. * record.c (cmd_record_start, set_record_command) (show_record_command, info_record_command, cmd_record_goto): Constify. * ravenscar-thread.c (set_ravenscar_command) (show_ravenscar_command): Constify. * utils.c (set_internal_problem_cmd, show_internal_problem_cmd): Constify. (add_internal_problem_command): Remove casts. * arc-tdep.c (maintenance_print_arc_command): Constify. * valprint.c (set_print, show_print, set_print_raw) (show_print_raw): Constify. * maint.c (maintenance_command, maintenance_info_command) (maintenance_print_command, maintenance_set_cmd) (maintenance_show_cmd, set_per_command_cmd) (show_per_command_cmd, maintenance_check_command): Constify. * language.c (set_check, show_check): Constify. * typeprint.c (show_print_type, set_print_type): Constify. * go32-nat.c (go32_info_dos_command): Constify.
2017-10-04Add missing-END_CATCH detection/protection (to gdb's TRY/CATCH/END_CATCH)Pedro Alves1-0/+1
While we still have cleanups (i.e., make_cleanup & co), we must be sure to add END_CATCH at the end of a TRY/CATCH/END_CATCH construct. However, it's currently too easy to miss adding the END_CATCH, because the code compiles anyway without it. I realized this when I noticed that another patch I was working on missed several adding END_CATCH in several new TRY/CATCH uses. This commit fixes that by making TRY open a new scope that is only closed by END_CATCH. This way, if you forget to add the END_CATCH, then compilation fails due to the unbalanced curly braces. This caught a couple places where we were missing END_CATCH in current master, also fixed by the patch. gdb/ChangeLog: 2017-10-04 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (complete_command): Add missing END_CATCH. * common/common-exceptions.h (TRY): Open an outermost scope. Expand intro comment. (CATCH): Reindent. (END_CATCH): Close the outermost scope. * completer.c (complete_line_internal): Add missing END_CATCH.
2017-10-04Implement "set cwd" command on GDBSergio Durigan Junior1-3/+5
This commit adds new "set/show cwd" commands, which are used to set/show the current working directory of the inferior that will be started. The idea here is that "set cwd" will become the de facto way of setting the inferior's cwd. Currently, the user can use "cd" for that, but there are side effects: with "cd", GDB also switches to another directory, and that can impact the loading of scripts and other files. With "set cwd", we separate the logic into a new command. To maintain backward compatibility, if the user issues a "cd" command but doesn't use "set cwd", then the inferior's cwd will still be changed according to what the user specified. However, "set cwd" has precedence over "cd", so it can always be used to override it. "set cwd" works in the following way: - If the user sets the inferior's cwd by using "set cwd", then this directory is saved into current_inferior ()->cwd and is used when the inferior is started (see below). - If the user doesn't set the inferior's cwd by using "set cwd", but rather use the "cd" command as before, then this directory is inherited by the inferior because GDB will have chdir'd into it. On Unix-like hosts, the way the directory is changed before the inferior execution is by expanding the user set directory before the fork, and then "chdir" after the call to fork/vfork on "fork_inferior", but before the actual execution. On Windows, the inferior cwd set by the user is passed directly to the CreateProcess call, which takes care of the actual chdir for us. This way, we'll make sure that GDB's cwd is not affected by the user set cwd. gdb/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS (New commands): Mention "set/show cwd". * cli/cli-cmds.c (_initialize_cli_cmds): Mention "set cwd" on "cd" command's help text. * common/common-inferior.h (get_inferior_cwd): New prototype. * infcmd.c (inferior_cwd_scratch): New global variable. (set_inferior_cwd): New function. (get_inferior_cwd): Likewise. (set_cwd_command): Likewise. (show_cwd_command): Likewise. (_initialize_infcmd): Add "set/show cwd" commands. * inferior.h (class inferior) <cwd>: New field. * nat/fork-inferior.c: Include "gdb_tilde_expand.h". (fork_inferior): Change inferior's cwd before its execution. * windows-nat.c (windows_create_inferior): Pass inferior's cwd to CreateProcess. gdb/gdbserver/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * inferiors.c (current_inferior_cwd): New global variable. (get_inferior_cwd): New function. * inferiors.h (struct process_info) <cwd>: New field. gdb/doc/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (Starting your Program) <The working directory.>: Mention new "set cwd" command. (Working Directory) <Your Program's Working Directory>: Rephrase to explain that "set cwd" exists and is the default way to change the inferior's cwd. gdb/testsuite/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/set-cwd.c: New file. * gdb.base/set-cwd.exp: Likewise.
2017-09-27Constify cd_commandTom Tromey2-2/+2
gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * cli/cli-cmds.h (cd_command): Constify. * cli/cli-cmds.c (cd_command): Constify.
2017-09-27Constify some linespec functionsTom Tromey1-2/+2
This changes a few linespec functions to work on "const char *" and then fixes up all the callers. This allows further constification elsewhere. gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * tracepoint.c (info_scope_command): Constify. * python/python.c (gdbpy_decode_line): Constify. * python/py-breakpoint.c (bppy_init): Constify. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Constify. * location.h: (new_linespec_location) (string_to_event_location_basic, string_to_event_location): Constify. * location.c (new_linespec_location) (string_to_event_location_basic, string_to_event_location): Constify. * linespec.h (decode_line_with_current_source) (decode_line_with_last_displayed, linespec_lex_to_end): Constify. * linespec.c (linespec_lex_to_end) (decode_line_with_current_source) (decode_line_with_last_displayed): Constify. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Constify. * cli/cli-cmds.c (edit_command, list_command): Constify. * breakpoint.h (until_break_command, watch_command_wrapper) (awatch_command_wrapper, rwatch_command_wrapper) (init_ada_exception_breakpoint): Constify. * breakpoint.c (break_command_1, dprintf_command) (break_range_command, watch_command_wrapper) (rwatch_command_wrapper, awatch_command_wrapper) (until_break_command, init_ada_exception_breakpoint) (strace_marker_create_sals_from_location, trace_command) (ftrace_command, strace_command, struct tracepoint): Constify. * ax-gdb.c (agent_command_1): Constify. * ada-lang.c (ada_exception_sal): Constify.
2017-09-27Constify some commands in cli-logging.cTom Tromey1-3/+3
gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * cli/cli-logging.c (set_logging_on, set_logging_off): Constify.
2017-09-27Constify user_defined_commandTom Tromey1-1/+1
gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * cli/cli-script.c (user_defined_command): Constify.
2017-09-27Constify commands in cli-dump.cTom Tromey1-16/+16
gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * cli/cli-dump.c (dump_memory_command, dump_value_command) (dump_srec_memory, dump_srec_value, dump_ihex_memory) (dump_ihex_value, dump_verilog_memory, dump_verilog_value) (dump_tekhex_memory, dump_tekhex_value, dump_binary_memory) (dump_binary_value, append_binary_memory, append_binary_value): Constify. (struct dump_context) <func>: Constify. (add_dump_command): Update.
2017-09-27Constify some commands in cli-cmds.cTom Tromey1-9/+5
gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * cli/cli-cmds.c (show_version, show_configuration) (source_command, show_user): Constify.
2017-09-27Constify not_just_help_class_commandTom Tromey2-2/+2
gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * command.h (not_just_help_class_command): Update. * cli/cli-decode.h (not_just_help_class_command): Update. * cli/cli-decode.c (not_just_help_class_command): Constify.
2017-09-27Add add_cmd function overloadsTom Tromey4-24/+77
This adds two add_cmd overloads: one whose callback takes a const char *, and one that doesn't accept a function at all. The no-function overload was introduced to avoid ambiguity when NULL was passed as the function. Long term the goal is for all commands to take const arguments, and for the non-const variants to be removed entirely. gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * cli/cli-decode.c (add_cmd, set_cmd_cfunc): New function overloads. (do_add_cmd): Rename from add_cmd. Don't call set_cmd_cfunc. (do_const_cfunc): New function. (cmd_cfunc_eq): New overload. (cli_user_command_p): Check do_const_cfunc. * cli/cli-decode.h (struct cmd_list_element) <function>: New field const_cfunc. * command.h (add_cmd): Add const overload and no-function overload. (set_cmd_cfunc): Add const overload. (cmd_const_cfunc_ftype): Declare. (cmd_cfunc_eq): Add const overload. * breakpoint.c, cli-cmds.c, cli-dump.c, guile/scm-cmd.c, python/py-cmd.c, target.c, tracepoint.c: Use no-function add_cmd overload.
2017-09-22Get rid of "gdb_dirbuf" and use "getcwd (NULL, 0)"Sergio Durigan Junior1-5/+12
Currently we have "current_directory" and "gdb_dirbuf" globals, which means that we basically have two possible places to consult when we want to know GDB's current working directory. This is not ideal and can lead to confusion. Moreover, the way we're using "gdb_difbuf" along with "getcwd" is problematic because we declare the buffer with "1024" elements hardcoded, which does not take into account longer pathnames that are possible in many filesystems. Using "PATH_MAX" would also not be a solution because of portability problems. Therefore, the best solution is to rely on the fact that "getcwd (NULL, 0)" will "do the right thing" and return a heap-allocated string containing the full path. With the new "getcwd" module from gnulib, it is now possible to do that without worrying about breaking some host. With this patch "current_directory" is now the only place to check for GDB's cwd. Reviewed-by: Pedro Alves <palves@redhat.com> gdb/ChangeLog: 2017-09-22 Sergio Durigan Junior <sergiodj@redhat.com> * cli/cli-cmds.c (pwd_command): Use "getcwd (NULL, 0)". (cd_command): Likewise. Free "current_directory" before assigning to it. * main.c (captured_main_1): Use "getcwd (NULL, 0)". * mi/mi-cmd-env.c (mi_cmd_env_pwd): Likewise. * top.c (gdb_dirbuf): Remove global declaration. * top.h (gdb_dirbuf): Likewise.
2017-09-20Make "list ambiguous" show symbol names tooPedro Alves1-8/+21
Currently, with an ambiguous "list first,last", we get: (gdb) list bar,main Specified first line 'bar' is ambiguous: file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97 file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98 This commit makes gdb's output above a bit clearer by printing the symbol name as well: (gdb) list bar,main Specified first line 'bar' is ambiguous: file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97, symbol: "bar(A)" file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98, symbol: "bar(B)" And while at it, makes gdb print the symbol name when actually listing multiple locations too. I.e., before (with "set listsize 2"): (gdb) list bar file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97 96 97 int bar (A) { return 11; } file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98 97 int bar (A) { return 11; } 98 int bar (B) { return 22; } After: (gdb) list bar file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97, symbol: "bar(A)" 96 97 int bar (A) { return 11; } file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98, symbol: "bar(B)" 97 int bar (A) { return 11; } 98 int bar (B) { return 22; } Currently, the result of decoding a linespec loses information about the original symbol that was found. All we end up with is an address. This makes it difficult to find the original symbol again to get at its print name. Fix that by storing a pointer to the symbol in the sal. We already store the symtab and obj_section, so it feels like a natural progression to me. This avoids having to do any extra symbol lookup too. gdb/ChangeLog: 2017-09-20 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (list_command): Use print_sal_location. (print_sal_location): New function. (ambiguous_line_spec): Use print_sal_location. * linespec.c (symbol_to_sal): Record the symbol in the sal. * symtab.c (find_function_start_sal): Likewise. * symtab.h (symtab_and_line::symbol): New field. gdb/testsuite/ChangeLog: 2017-09-20 Pedro Alves <palves@redhat.com> * gdb.base/list-ambiguous.exp (test_list_ambiguous_symbol): Expect symbol names in gdb's output. * gdb.cp/overload.exp ("list all overloads"): Likewise.
2017-09-11Replace clear_hook_in_cleanup with scoped_restore_hook_inTom Tromey1-10/+21
This removes clear_hook_in_cleanup in favor of a scoped_restore-like class. scoped_restore itself can't be used because hook_in is a bitfield. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * cli/cli-script.c (class scoped_restore_hook_in): New. (clear_hook_in_cleanup): Remove. (execute_cmd_pre_hook, execute_cmd_post_hook): Use scoped_restore_hook_in.
2017-09-11Replace interp_set_temp with scoped_restore_interpTom Tromey1-9/+1
This removes interp_set_temp and an associated cleanup, in favor of a new RAII class, scoped_restore_interp. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * cli/cli-script.c (restore_interp): Remove. (read_command_lines): Use scoped_restore_interp. * interps.c (scoped_restore_interp::set_temp): Rename from interp_set_temp. * interps.h (class scoped_restore_interp): New. (interp_set_temp): Remove.
2017-09-11Make extract_arg return a std::stringTom Tromey2-15/+12
Change extract_arg to return a std::string and fix up all the users. I think string is mildly better than unique_xmalloc_ptr<char>, when possible, because it provides a more robust API. I changed the error messages emitted from find_location_by_number to avoid either writing to a string or an extra allocation; this can be changed but I thought that the new message was not any less clear. You can see an example in the testsuite patch. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * demangle.c (demangle_command): Update. * breakpoint.c (disable_command): Update. (enable_command): Update. (find_location_by_number): Make "number" const. Use get_number_trailer. * cli/cli-utils.c (extract_arg): Return std::string. * probe.c (parse_probe_linespec): Update. Change types. (collect_probes): Take string arguments. (parse_probe_linespec): Likewise. (info_probes_for_ops): Update. (enable_probes_command): Update. (disable_probes_command): Update. * break-catch-sig.c (catch_signal_split_args): Update. * mi/mi-parse.c (mi_parse): Update. testsuite/ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * gdb.base/ena-dis-br.exp (test_ena_dis_br): Update test.
2017-09-11Rename _const functions to use overloading insteadTom Tromey6-21/+21
This renames a few functions -- skip_spaces_const, skip_to_space_const, get_number_const, extract_arg_const -- to drop the "_const" suffix and instead rely on overloading. This makes future const fixes simpler by reducing the number of lines that must be changed. I think it is also not any less clear, as all these functions have the same interface as their non-const versions by design. Furthermore there's an example of using an overload in-tree already, namely check_for_argument. This patch was largely created using some perl one-liners; then a few fixes were applied by hand. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * common/common-utils.h (skip_to_space): Remove macro, redeclare as function. (skip_to_space): Rename from skip_to_space_const. * common/common-utils.c (skip_to_space): New function. (skip_to_space): Rename from skip_to_space_const. * cli/cli-utils.h (get_number): Rename from get_number_const. (extract_arg): Rename from extract_arg_const. * cli/cli-utils.c (get_number): Rename from get_number_const. (extract_arg): Rename from extract_arg_const. (number_or_range_parser::get_number): Use ::get_number. * aarch64-linux-tdep.c, ada-lang.c, arm-linux-tdep.c, ax-gdb.c, break-catch-throw.c, breakpoint.c, cli/cli-cmds.c, cli/cli-dump.c, cli/cli-script.c, cli/cli-setshow.c, compile/compile.c, completer.c, demangle.c, disasm.c, findcmd.c, linespec.c, linux-tdep.c, linux-thread-db.c, location.c, mi/mi-parse.c, minsyms.c, nat/linux-procfs.c, printcmd.c, probe.c, python/py-breakpoint.c, record.c, rust-exp.y, serial.c, stack.c, stap-probe.c, tid-parse.c, tracepoint.c: Update all callers.
2017-09-09Remove unnecessary function prototypes.John Baldwin5-14/+0
These prototypes were required when compiling GDB as C but are not required for C++. gdb/ChangeLog: * aarch64-linux-nat.c: Remove _initialize_aarch64_linux_nat prototype. * aarch64-linux-tdep.c: Remove _initialize_aarch64_linux_tdep prototype. * aarch64-newlib-tdep.c: Remove _initialize_aarch64_newlib_tdep prototype. * aarch64-tdep.c: Remove _initialize_aarch64_tdep prototype. * ada-exp.y: Remove _initialize_ada_exp prototype. * ada-lang.c: Remove _initialize_ada_language prototype. * ada-tasks.c: Remove _initialize_tasks prototype. * addrmap.c: Remove _initialize_addrmap prototype. * agent.c: Remove _initialize_agent prototype. * aix-thread.c: Remove _initialize_aix_thread prototype. * alpha-bsd-nat.c: Remove _initialize_alphabsd_nat prototype. * alpha-linux-nat.c: Remove _initialize_alpha_linux_nat prototype. * alpha-linux-tdep.c: Remove _initialize_alpha_linux_tdep prototype. * alpha-nbsd-tdep.c: Remove _initialize_alphanbsd_tdep prototype. * alpha-obsd-tdep.c: Remove _initialize_alphaobsd_tdep prototype. * alpha-tdep.c: Remove _initialize_alpha_tdep prototype. * amd64-darwin-tdep.c: Remove _initialize_amd64_darwin_tdep prototype. * amd64-dicos-tdep.c: Remove _initialize_amd64_dicos_tdep prototype. * amd64-fbsd-nat.c: Remove _initialize_amd64fbsd_nat prototype. * amd64-fbsd-tdep.c: Remove _initialize_amd64fbsd_tdep prototype. * amd64-linux-nat.c: Remove _initialize_amd64_linux_nat prototype. * amd64-linux-tdep.c: Remove _initialize_amd64_linux_tdep prototype. * amd64-nbsd-nat.c: Remove _initialize_amd64nbsd_nat prototype. * amd64-nbsd-tdep.c: Remove _initialize_amd64nbsd_tdep prototype. * amd64-obsd-nat.c: Remove _initialize_amd64obsd_nat prototype. * amd64-obsd-tdep.c: Remove _initialize_amd64obsd_tdep prototype. * amd64-sol2-tdep.c: Remove _initialize_amd64_sol2_tdep prototype. * amd64-tdep.c: Remove _initialize_amd64_tdep prototype. * amd64-windows-nat.c: Remove _initialize_amd64_windows_nat prototype. * amd64-windows-tdep.c: Remove _initialize_amd64_windows_tdep prototype. * annotate.c: Remove _initialize_annotate prototype. * arc-newlib-tdep.c: Remove _initialize_arc_newlib_tdep prototype. * arc-tdep.c: Remove _initialize_arc_tdep prototype. * arch-utils.c: Remove _initialize_gdbarch_utils prototype. * arm-linux-nat.c: Remove _initialize_arm_linux_nat prototype. * arm-linux-tdep.c: Remove _initialize_arm_linux_tdep prototype. * arm-nbsd-tdep.c: Remove _initialize_arm_netbsd_tdep prototype. * arm-obsd-tdep.c: Remove _initialize_armobsd_tdep prototype. * arm-symbian-tdep.c: Remove _initialize_arm_symbian_tdep prototype. * arm-tdep.c: Remove _initialize_arm_tdep prototype. * arm-wince-tdep.c: Remove _initialize_arm_wince_tdep prototype. * auto-load.c: Remove _initialize_auto_load prototype. * auxv.c: Remove _initialize_auxv prototype. * avr-tdep.c: Remove _initialize_avr_tdep prototype. * ax-gdb.c: Remove _initialize_ax_gdb prototype. * bfin-linux-tdep.c: Remove _initialize_bfin_linux_tdep prototype. * bfin-tdep.c: Remove _initialize_bfin_tdep prototype. * break-catch-sig.c: Remove _initialize_break_catch_sig prototype. * break-catch-syscall.c: Remove _initialize_break_catch_syscall prototype. * break-catch-throw.c: Remove _initialize_break_catch_throw prototype. * breakpoint.c: Remove _initialize_breakpoint prototype. * bsd-uthread.c: Remove _initialize_bsd_uthread prototype. * btrace.c: Remove _initialize_btrace prototype. * charset.c: Remove _initialize_charset prototype. * cli/cli-cmds.c: Remove _initialize_cli_cmds prototype. * cli/cli-dump.c: Remove _initialize_cli_dump prototype. * cli/cli-interp.c: Remove _initialize_cli_interp prototype. * cli/cli-logging.c: Remove _initialize_cli_logging prototype. * cli/cli-script.c: Remove _initialize_cli_script prototype. * coff-pe-read.c: Remove _initialize_coff_pe_read prototype. * coffread.c: Remove _initialize_coffread prototype. * compile/compile.c: Remove _initialize_compile prototype. * complaints.c: Remove _initialize_complaints prototype. * completer.c: Remove _initialize_completer prototype. * copying.awk: Remove _initialize_copying prototype. * copying.c: Regenerate. * core-regset.c: Remove _initialize_core_regset prototype. * corefile.c: Remove _initialize_core prototype. * corelow.c: Remove _initialize_corelow prototype. * cp-abi.c: Remove _initialize_cp_abi prototype. * cp-namespace.c: Remove _initialize_cp_namespace prototype. * cp-support.c: Remove _initialize_cp_support prototype. * cp-valprint.c: Remove _initialize_cp_valprint prototype. * cris-linux-tdep.c: Remove _initialize_cris_linux_tdep prototype. * cris-tdep.c: Remove _initialize_cris_tdep prototype. * ctf.c: Remove _initialize_ctf prototype. * d-lang.c: Remove _initialize_d_language prototype. * darwin-nat-info.c: Remove _initialize_darwin_info_commands prototype. * darwin-nat.c: Remove _initialize_darwin_inferior prototype. * dbxread.c: Remove _initialize_dbxread prototype. * dcache.c: Remove _initialize_dcache prototype. * demangle.c: Remove _initialize_demangler prototype. * disasm-selftests.c: Remove _initialize_disasm_selftests prototype. * disasm.c: Remove _initialize_disasm prototype. * dtrace-probe.c: Remove _initialize_dtrace_probe prototype. * dummy-frame.c: Remove _initialize_dummy_frame prototype. * dwarf2-frame-tailcall.c: Remove _initialize_tailcall_frame prototype. * dwarf2-frame.c: Remove _initialize_dwarf2_frame prototype. * dwarf2expr.c: Remove _initialize_dwarf2expr prototype. * dwarf2loc.c: Remove _initialize_dwarf2loc prototype. * dwarf2read.c: Remove _initialize_dwarf2_read prototype. * elfread.c: Remove _initialize_elfread prototype. * exec.c: Remove _initialize_exec prototype. * extension.c: Remove _initialize_extension prototype. * f-lang.c: Remove _initialize_f_language prototype. * f-valprint.c: Remove _initialize_f_valprint prototype. * fbsd-nat.c: Remove _initialize_fbsd_nat prototype. * fbsd-tdep.c: Remove _initialize_fbsd_tdep prototype. * filesystem.c: Remove _initialize_filesystem prototype. * findcmd.c: Remove _initialize_mem_search prototype. * fork-child.c: Remove _initialize_fork_child prototype. * frame-base.c: Remove _initialize_frame_base prototype. * frame-unwind.c: Remove _initialize_frame_unwind prototype. * frame.c: Remove _initialize_frame prototype. * frv-linux-tdep.c: Remove _initialize_frv_linux_tdep prototype. * frv-tdep.c: Remove _initialize_frv_tdep prototype. * ft32-tdep.c: Remove _initialize_ft32_tdep prototype. * gcore.c: Remove _initialize_gcore prototype. * gdb_bfd.c: Remove _initialize_gdb_bfd prototype. * gdbarch.c: Regenerate. * gdbarch.sh: Remove _initialize_gdbarch prototype. * gdbtypes.c: Remove _initialize_gdbtypes prototype. * gnu-nat.c: Remove _initialize_gnu_nat prototype. * gnu-v2-abi.c: Remove _initialize_gnu_v2_abi prototype. * gnu-v3-abi.c: Remove _initialize_gnu_v3_abi prototype. * go-lang.c: Remove _initialize_go_language prototype. * go32-nat.c: Remove _initialize_go32_nat prototype. * guile/guile.c: Remove _initialize_guile prototype. * h8300-tdep.c: Remove _initialize_h8300_tdep prototype. * hppa-linux-nat.c: Remove _initialize_hppa_linux_nat prototype. * hppa-linux-tdep.c: Remove _initialize_hppa_linux_tdep prototype. * hppa-nbsd-nat.c: Remove _initialize_hppanbsd_nat prototype. * hppa-nbsd-tdep.c: Remove _initialize_hppanbsd_tdep prototype. * hppa-obsd-nat.c: Remove _initialize_hppaobsd_nat prototype. * hppa-obsd-tdep.c: Remove _initialize_hppaobsd_tdep prototype. * hppa-tdep.c: Remove _initialize_hppa_tdep prototype. * i386-bsd-nat.c: Remove _initialize_i386bsd_nat prototype. * i386-cygwin-tdep.c: Remove _initialize_i386_cygwin_tdep prototype. * i386-darwin-tdep.c: Remove _initialize_i386_darwin_tdep prototype. * i386-dicos-tdep.c: Remove _initialize_i386_dicos_tdep prototype. * i386-fbsd-nat.c: Remove _initialize_i386fbsd_nat prototype. * i386-fbsd-tdep.c: Remove _initialize_i386fbsd_tdep prototype. * i386-gnu-nat.c: Remove _initialize_i386gnu_nat prototype. * i386-gnu-tdep.c: Remove _initialize_i386gnu_tdep prototype. * i386-linux-nat.c: Remove _initialize_i386_linux_nat prototype. * i386-linux-tdep.c: Remove _initialize_i386_linux_tdep prototype. * i386-nbsd-nat.c: Remove _initialize_i386nbsd_nat prototype. * i386-nbsd-tdep.c: Remove _initialize_i386nbsd_tdep prototype. * i386-nto-tdep.c: Remove _initialize_i386nto_tdep prototype. * i386-obsd-nat.c: Remove _initialize_i386obsd_nat prototype. * i386-obsd-tdep.c: Remove _initialize_i386obsd_tdep prototype. * i386-sol2-nat.c: Remove _initialize_amd64_sol2_nat prototype. * i386-sol2-tdep.c: Remove _initialize_amd64_sol2_tdep prototype. * i386-tdep.c: Remove _initialize_i386_tdep prototype. * i386-windows-nat.c: Remove _initialize_i386_windows_nat prototype. * ia64-libunwind-tdep.c: Remove _initialize_libunwind_frame prototype. * ia64-linux-nat.c: Remove _initialize_ia64_linux_nat prototype. * ia64-linux-tdep.c: Remove _initialize_ia64_linux_tdep prototype. * ia64-tdep.c: Remove _initialize_ia64_tdep prototype. * ia64-vms-tdep.c: Remove _initialize_ia64_vms_tdep prototype. * infcall.c: Remove _initialize_infcall prototype. * infcmd.c: Remove _initialize_infcmd prototype. * inferior.c: Remove _initialize_inferiors prototype. * inflow.c: Remove _initialize_inflow prototype. * infrun.c: Remove _initialize_infrun prototype. * interps.c: Remove _initialize_interpreter prototype. * iq2000-tdep.c: Remove _initialize_iq2000_tdep prototype. * jit.c: Remove _initialize_jit prototype. * language.c: Remove _initialize_language prototype. * linux-fork.c: Remove _initialize_linux_fork prototype. * linux-nat.c: Remove _initialize_linux_nat prototype. * linux-tdep.c: Remove _initialize_linux_tdep prototype. * linux-thread-db.c: Remove _initialize_thread_db prototype. * lm32-tdep.c: Remove _initialize_lm32_tdep prototype. * m2-lang.c: Remove _initialize_m2_language prototype. * m32c-tdep.c: Remove _initialize_m32c_tdep prototype. * m32r-linux-nat.c: Remove _initialize_m32r_linux_nat prototype. * m32r-linux-tdep.c: Remove _initialize_m32r_linux_tdep prototype. * m32r-tdep.c: Remove _initialize_m32r_tdep prototype. * m68hc11-tdep.c: Remove _initialize_m68hc11_tdep prototype. * m68k-bsd-nat.c: Remove _initialize_m68kbsd_nat prototype. * m68k-bsd-tdep.c: Remove _initialize_m68kbsd_tdep prototype. * m68k-linux-nat.c: Remove _initialize_m68k_linux_tdep prototype. * m68k-linux-tdep.c: Remove _initialize_m68k_linux_tdep prototype. * m68k-tdep.c: Remove _initialize_m68k_tdep prototype. * m88k-bsd-nat.c: Remove _initialize_m68kbsd_nat prototype. * m88k-tdep.c: Remove _initialize_m68kbsd_tdep prototype. * machoread.c: Remove _initialize_machoread prototype. * macrocmd.c: Remove _initialize_macrocmd prototype. * macroscope.c: Remove _initialize_macroscope prototype. * maint.c: Remove _initialize_maint_cmds prototype. * mdebugread.c: Remove _initialize_mdebugread prototype. * memattr.c: Remove _initialize_mem prototype. * mep-tdep.c: Remove _initialize_mep_tdep prototype. * mi/mi-cmd-env.c: Remove _initialize_mi_cmd_env prototype. * mi/mi-cmds.c: Remove _initialize_mi_cmds prototype. * mi/mi-interp.c: Remove _initialize_mi_interp prototype. * mi/mi-main.c: Remove _initialize_mi_main prototype. * microblaze-linux-tdep.c: Remove _initialize_microblaze_linux_tdep prototype. * microblaze-tdep.c: Remove _initialize_microblaze_tdep prototype. * mips-fbsd-nat.c: Remove _initialize_mips_fbsd_nat prototype. * mips-fbsd-tdep.c: Remove _initialize_mips_fbsd_tdep prototype. * mips-linux-nat.c: Remove _initialize_mips_linux_nat prototype. * mips-linux-tdep.c: Remove _initialize_mips_linux_tdep prototype. * mips-nbsd-nat.c: Remove _initialize_mipsnbsd_nat prototype. * mips-nbsd-tdep.c: Remove _initialize_mipsnbsd_tdep prototype. * mips-sde-tdep.c: Remove _initialize_mips_sde_tdep prototype. * mips-tdep.c: Remove _initialize_mips_tdep prototype. * mips64-obsd-nat.c: Remove _initialize_mips64obsd_nat prototype. * mips64-obsd-tdep.c: Remove _initialize_mips64obsd_tdep prototype. * mipsread.c: Remove _initialize_mipsread prototype. * mn10300-linux-tdep.c: Remove _initialize_mn10300_linux_tdep prototype. * mn10300-tdep.c: Remove _initialize_mn10300_tdep prototype. * moxie-tdep.c: Remove _initialize_moxie_tdep prototype. * msp430-tdep.c: Remove _initialize_msp430_tdep prototype. * mt-tdep.c: Remove _initialize_mt_tdep prototype. * nds32-tdep.c: Remove _initialize_nds32_tdep prototype. * nios2-linux-tdep.c: Remove _initialize_nios2_linux_tdep prototype. * nios2-tdep.c: Remove _initialize_nios2_tdep prototype. * nto-procfs.c: Remove _initialize_procfs prototype. * nto-tdep.c: Remove _initialize_nto_tdep prototype. * objc-lang.c: Remove _initialize_objc_language prototype. * objfiles.c: Remove _initialize_objfiles prototype. * observer.c: Remove observer_test_first_notification_function, observer_test_second_notification_function, observer_test_third_notification_function, and _initialize_observer prototypes. * opencl-lang.c: Remove _initialize_opencl_language prototypes. * osabi.c: Remove _initialize_gdb_osabi prototype. * osdata.c: Remove _initialize_osdata prototype. * p-valprint.c: Remove _initialize_pascal_valprint prototype. * parse.c: Remove _initialize_parse prototype. * ppc-fbsd-nat.c: Remove _initialize_ppcfbsd_nat prototype. * ppc-fbsd-tdep.c: Remove _initialize_ppcfbsd_tdep prototype. * ppc-linux-nat.c: Remove _initialize_ppc_linux_nat prototype. * ppc-linux-tdep.c: Remove _initialize_ppc_linux_tdep prototype. * ppc-nbsd-nat.c: Remove _initialize_ppcnbsd_nat prototype. * ppc-nbsd-tdep.c: Remove _initialize_ppcnbsd_tdep prototype. * ppc-obsd-nat.c: Remove _initialize_ppcobsd_nat prototype. * ppc-obsd-tdep.c: Remove _initialize_ppcobsd_tdep prototype. * printcmd.c: Remove _initialize_printcmd prototype. * probe.c: Remove _initialize_probe prototype. * proc-api.c: Remove _initialize_proc_api prototype. * proc-events.c: Remove _initialize_proc_events prototype. * proc-service.c: Remove _initialize_proc_service prototype. * procfs.c: Remove _initialize_procfs prototype. * psymtab.c: Remove _initialize_psymtab prototype. * python/python.c: Remove _initialize_python prototype. * ravenscar-thread.c: Remove _initialize_ravenscar prototype. * record-btrace.c: Remove _initialize_record_btrace prototype. * record-full.c: Remove _initialize_record_full prototype. * record.c: Remove _initialize_record prototype. * regcache.c: Remove _initialize_regcache prototype. * reggroups.c: Remove _initialize_reggroup prototype. * remote-notif.c: Remove _initialize_notif prototype. * remote-sim.c: Remove _initialize_remote_sim prototype. * remote.c: Remove _initialize_remote prototype. * reverse.c: Remove _initialize_reverse prototype. * rl78-tdep.c: Remove _initialize_rl78_tdep prototype. * rs6000-aix-tdep.c: Remove _initialize_rs6000_aix_tdep prototype. * rs6000-lynx178-tdep.c: Remove _initialize_rs6000_lynx178_tdep prototype. * rs6000-nat.c: Remove _initialize_rs6000_nat prototype. * rs6000-tdep.c: Remove _initialize_rs6000_tdep prototype. * rust-exp.y: Remove _initialize_rust_exp prototype. * rx-tdep.c: Remove _initialize_rx_tdep prototype. * s390-linux-nat.c: Remove _initialize_s390_nat prototype. * s390-linux-tdep.c: Remove _initialize_s390_tdep prototype. * score-tdep.c: Remove _initialize_score_tdep prototype. * selftest-arch.c: Remove _initialize_selftests_foreach_arch prototype. * ser-go32.c: Remove _initialize_ser_dos prototype. * ser-mingw.c: Remove _initialize_ser_windows prototype. * ser-pipe.c: Remove _initialize_ser_pipe prototype. * ser-tcp.c: Remove _initialize_ser_tcp prototype. * ser-unix.c: Remove _initialize_ser_hardwire prototype. * serial.c: Remove _initialize_serial prototype. * sh-linux-tdep.c: Remove _initialize_sh_linux_tdep prototype. * sh-nbsd-nat.c: Remove _initialize_shnbsd_nat prototype. * sh-nbsd-tdep.c: Remove _initialize_shnbsd_tdep prototype. * sh-tdep.c: Remove _initialize_sh_tdep prototype. * skip.c: Remove _initialize_step_skip prototype. * sol-thread.c: Remove _initialize_sol_thread prototype. * solib-aix.c: Remove _initialize_solib_aix prototype. * solib-darwin.c: Remove _initialize_darwin_solib prototype. * solib-dsbt.c: Remove _initialize_dsbt_solib prototype. * solib-frv.c: Remove _initialize_frv_solib prototype. * solib-spu.c: Remove _initialize_spu_solib prototype. * solib-svr4.c: Remove _initialize_svr4_solib prototype. * solib-target.c: Remove _initialize_solib_target prototype. * solib.c: Remove _initialize_solib prototype. * source.c: Remove _initialize_source prototype. * sparc-linux-nat.c: Remove _initialize_sparc_linux_nat prototype. * sparc-linux-tdep.c: Remove _initialize_sparc_linux_tdep prototype. * sparc-nat.c: Remove _initialize_sparc_nat prototype. * sparc-nbsd-nat.c: Remove _initialize_sparcnbsd_nat prototype. * sparc-nbsd-tdep.c: Remove _initialize_sparcnbsd_tdep prototype. * sparc-obsd-tdep.c: Remove _initialize_sparc32obsd_tdep prototype. * sparc-sol2-nat.c: Remove _initialize_sparc_sol2_nat prototype. * sparc-sol2-tdep.c: Remove _initialize_sparc_sol2_tdep prototype. * sparc-tdep.c: Remove _initialize_sparc_tdep prototype. * sparc64-fbsd-nat.c: Remove _initialize_sparc64fbsd_nat prototype. * sparc64-fbsd-tdep.c: Remove _initialize_sparc64fbsd_tdep prototype. * sparc64-linux-nat.c: Remove _initialize_sparc64_linux_nat prototype. * sparc64-linux-tdep.c: Remove _initialize_sparc64_linux_tdep prototype. * sparc64-nat.c: Remove _initialize_sparc64_nat prototype. * sparc64-nbsd-nat.c: Remove _initialize_sparc64nbsd_nat prototype. * sparc64-nbsd-tdep.c: Remove _initialize_sparc64nbsd_tdep prototype. * sparc64-obsd-nat.c: Remove _initialize_sparc64obsd_nat prototype. * sparc64-obsd-tdep.c: Remove _initialize_sparc64obsd_tdep prototype. * sparc64-sol2-tdep.c: Remove _initialize_sparc64_sol2_tdep prototype. * spu-linux-nat.c: Remove _initialize_spu_nat prototype. * spu-multiarch.c: Remove _initialize_spu_multiarch prototype. * spu-tdep.c: Remove _initialize_spu_tdep prototype. * stabsread.c: Remove _initialize_stabsread prototype. * stack.c: Remove _initialize_stack prototype. * stap-probe.c: Remove _initialize_stap_probe prototype. * std-regs.c: Remove _initialize_frame_reg prototype. * symfile-debug.c: Remove _initialize_symfile_debug prototype. * symfile-mem.c: Remove _initialize_symfile_mem prototype. * symfile.c: Remove _initialize_symfile prototype. * symmisc.c: Remove _initialize_symmisc prototype. * symtab.c: Remove _initialize_symtab prototype. * target-dcache.c: Remove _initialize_target_dcache prototype. * target-descriptions.c: Remove _initialize_target_descriptions prototype. * thread.c: Remove _initialize_thread prototype. * tic6x-linux-tdep.c: Remove _initialize_tic6x_linux_tdep prototype. * tic6x-tdep.c: Remove _initialize_tic6x_tdep prototype. * tilegx-linux-nat.c: Remove _initialize_tile_linux_nat prototype. * tilegx-linux-tdep.c: Remove _initialize_tilegx_linux_tdep prototype. * tilegx-tdep.c: Remove _initialize_tilegx_tdep prototype. * tracefile-tfile.c: Remove _initialize_tracefile_tfile prototype. * tracefile.c: Remove _initialize_tracefile prototype. * tracepoint.c: Remove _initialize_tracepoint prototype. * tui/tui-hooks.c: Remove _initialize_tui_hooks prototype. * tui/tui-interp.c: Remove _initialize_tui_interp prototype. * tui/tui-layout.c: Remove _initialize_tui_layout prototype. * tui/tui-regs.c: Remove _initialize_tui_regs prototype. * tui/tui-stack.c: Remove _initialize_tui_stack prototype. * tui/tui-win.c: Remove _initialize_tui_win prototype. * tui/tui.c: Remove _initialize_tui prototype. * typeprint.c: Remove _initialize_typeprint prototype. * user-regs.c: Remove _initialize_user_regs prototype. * utils.c: Remove _initialize_utils prototype. * v850-tdep.c: Remove _initialize_v850_tdep prototype. * valarith.c: Remove _initialize_valarith prototype. * valops.c: Remove _initialize_valops prototype. * valprint.c: Remove _initialize_valprint prototype. * value.c: Remove _initialize_values prototype. * varobj.c: Remove _initialize_varobj prototype. * vax-bsd-nat.c: Remove _initialize_vaxbsd_nat prototype. * vax-nbsd-tdep.c: Remove _initialize_vaxnbsd_tdep prototype. * vax-tdep.c: Remove _initialize_vax_tdep prototype. * windows-nat.c: Remove _initialize_windows_nat, _initialize_check_for_gdb_ini, and _initialize_loadable prototypes. * windows-tdep.c: Remove _initialize_windows_tdep prototype. * xcoffread.c: Remove _initialize_xcoffread prototype. * xml-support.c: Remove _initialize_xml_support prototype. * xstormy16-tdep.c: Remove _initialize_xstormy16_tdep prototype. * xtensa-linux-nat.c: Remove _initialize_xtensa_linux_nat prototype. * xtensa-linux-tdep.c: Remove _initialize_xtensa_linux_tdep prototype. * xtensa-tdep.c: Remove _initialize_xtensa_tdep prototype.
2017-09-04Introduce gdb_disassembly_flagsPedro Alves1-3/+4
For some reason I ended up staring at some of the "int flags" in btrace-related code, and I got confused because I had no clue what the flags where supposed to indicate. Fix that by using enum_flags, so that: #1 - it's clear from the type what the flags are about, and #2 - the compiler can catch mismatching mistakes gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (print_disassembly, disassemble_current_function) (disassemble_command): Use gdb_disassembly_flags instead of bare int. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn) (dump_insns, do_mixed_source_and_assembly_deprecated) (do_mixed_source_and_assembly, do_assembly_only, gdb_disassembly): Use gdb_disassembly_flags instead of bare int. * disasm.h (DISASSEMBLY_SOURCE_DEPRECATED, DISASSEMBLY_RAW_INSN) (DISASSEMBLY_OMIT_FNAME, DISASSEMBLY_FILENAME) (DISASSEMBLY_OMIT_PC, DISASSEMBLY_SOURCE) (DISASSEMBLY_SPECULATIVE): No longer macros. Instead they're... (enum gdb_disassembly_flag): ... values of this new enumeration. (gdb_disassembly_flags): Define. (gdb_disassembly) (gdb_pretty_print_disassembler::pretty_print_insn): Use it. * mi/mi-cmd-disas.c (mi_cmd_disassemble): Use gdb_disassembly_flags instead of bare int. * record-btrace.c (btrace_insn_history) (record_btrace_insn_history, record_btrace_insn_history_range) (record_btrace_insn_history_from): Use gdb_disassembly_flags instead of bare int. * record.c (get_insn_history_modifiers, cmd_record_insn_history): Use gdb_disassembly_flags instead of bare int. * target-debug.h (target_debug_print_gdb_disassembly_flags): Define. * target-delegates.c: Regenerate. * target.c (target_insn_history, target_insn_history_from) (target_insn_history_range): Use gdb_disassembly_flags instead of bare int. * target.h: Include "disasm.h". (struct target_ops) <to_insn_history, to_insn_history_from, to_insn_history_range>: Use gdb_disassembly_flags instead of bare int. (target_insn_history, target_insn_history_from) (target_insn_history_range): Use gdb_disassembly_flags instead of bare int.
2017-09-04Error out immediatly when using if command without args in command listSimon Marchi1-1/+2
When using "if" (or while) without args directly on gdb's command line, you get this: (gdb) if if/while commands require arguments When doing the same when entering a command list, you only get an error when the command is executed, when parse_exp_in_context_1 fails to evaluate the expression. (gdb) define foo Type commands for definition of "foo". End with a line saying just "end". >if >end >end (gdb) foo Argument required (expression to compute). I think it would make more sense to error out when inputting the command list directly: (gdb) define foo Type commands for definition of "foo". End with a line saying just "end". >if if/while commands require arguments. The only required change is to check whether args is an empty string in build_command_line. gdb/ChangeLog: * cli/cli-script.c (build_command_line): For if/while commands, check whether args is empty. gdb/testsuite/ChangeLog: * gdb.base/commands.exp: Call new procedure. (define_if_without_arg_test): New procedure.
2017-09-04Move command lines types/declarations to cli-script.hSimon Marchi1-1/+75
I think it would make more sense if the types and function declarations related to command lines were in cli-script.h rather than defs.h, since the related function definitions are in cli-script.c. I had to add a few includes here and there. I also had to rename the "lines" parameter of command_lines_deleter::operator(), because ncurses has a "#define lines ..." that was interfering when cli-script.h is included by some TUI source files that also include ncurses header files. gdb/ChangeLog: * cli/cli-script.h (enum misc_command_type): Move from defs.h. (enum command_control_type): Likewise. (struct command_line): Likewise. (free_command_lines): Likewise. (struct command_lines_deleter): Likewise. (command_line_up): Likewise. (read_command_lines): Likewise. (read_command_lines_1): Likewise. * defs.h (enum misc_command_type): Move to cli/cli-script.h. (enum command_control_type): Likewise. (struct command_line): Likewise. (free_command_lines): Likewise. (struct command_lines_deleter): Likewise. (command_line_up): Likewise. (read_command_lines): Likewise. (read_command_lines_1): Likewise. * breakpoint.h: Include cli/cli-script.h. * extension-priv.h: Likewise. * gdbcmd.h: Likewise.
2017-09-04Kill init_salPedro Alves1-4/+2
Instead, make symtab_and_line initialize its members itself. Many symtab_and_line declarations are moved to where the object is initialized at the same time both for clarity and to avoid double initialization. A few functions, like e.g., find_frame_sal are adjusted to return the sal using normal function return instead of an output parameter likewise to avoid having to default-construct a sal and then immediately have the object overwritten. gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * ada-lang.c (is_known_support_routine): Move sal declaration to where it is initialized. * breakpoint.c (create_internal_breakpoint, init_catchpoint) (parse_breakpoint_sals, decode_static_tracepoint_spec) (clear_command, update_static_tracepoint): Remove init_sal references. Move declarations closer to initializations. * cli/cli-cmds.c (list_command): Move sal declarations closer to initializations. * elfread.c (elf_gnu_ifunc_resolver_stop): Remove init_sal references. Move sal declarations closer to initializations. * frame.c (find_frame_sal): Return a symtab_and_line via function return instead of output parameter. Remove init_sal references. * frame.h (find_frame_sal): Return a symtab_and_line via function return instead of output parameter. * guile/scm-frame.c (gdbscm_frame_sal): Adjust. * guile/scm-symtab.c (stscm_make_sal_smob): Use in-place new instead of memset. (gdbscm_find_pc_line): Remove init_sal reference. * infcall.c (call_function_by_hand_dummy): Remove init_sal references. Move declarations closer to initializations. * infcmd.c (set_step_frame): Update. Move declarations closer to initializations. (finish_backward): Remove init_sal references. Move declarations closer to initializations. * infrun.c (process_event_stop_test, handle_step_into_function) (insert_hp_step_resume_breakpoint_at_frame) (insert_step_resume_breakpoint_at_caller): Likewise. * linespec.c (create_sals_line_offset, decode_digits_ordinary) (symbol_to_sal): Likewise. * probe.c (parse_probes_in_pspace): Remove init_sal reference. * python/py-frame.c (frapy_find_sal): Move sal declaration closer to its initialization. * reverse.c (save_bookmark_command): Use new/delete. Remove init_sal references. Move declarations closer to initializations. * source.c (get_current_source_symtab_and_line): Remove brace initialization. (set_current_source_symtab_and_line): Now takes the sal by const reference. Remove brace initialization. (line_info): Remove init_sal reference. * source.h (set_current_source_symtab_and_line): Now takes a symtab_and_line via const reference. * stack.c (set_current_sal_from_frame): Adjust. (print_frame_info): Adjust. (get_last_displayed_sal): Return the sal via function return instead of via output parameter. Simplify. (frame_info): Adjust. * stack.h (get_last_displayed_sal): Return the sal via function return instead of via output parameter. * symtab.c (init_sal): Delete. (find_pc_sect_line): Remove init_sal references. Move declarations closer to initializations. (find_function_start_sal): Remove init_sal references. Move declarations closer to initializations. * symtab.h (struct symtab_and_line): In-class initialize all fields. * tracepoint.c (set_traceframe_context) (print_one_static_tracepoint_marker): Remove init_sal references. Move declarations closer to initializations. * tui/tui-disasm.c (tui_show_disassem_and_update_source): Adjust. * tui/tui-stack.c (tui_show_frame_info): Adjust. Move declarations closer to initializations. * tui/tui-winsource.c (tui_update_source_window_as_is): Remove init_sal references. Adjust.
2017-09-04struct symtabs_and_lines -> std::vector<symtab_and_line>Pedro Alves1-100/+66
This replaces "struct symtabs_and_lines" with std::vector<symtab_and_line> in most cases. This removes a number of cleanups. In some cases, the sals objects do not own the sals they point at. Instead they point at some sal that lives on the stack. Typically something like this: struct symtab_and_line sal; struct symtabs_and_lines sals; // fill in sal sals.nelts = 1; sals.sals = &sal; // use sals Instead of switching those cases to std::vector too, such usages are replaced by gdb::array_view<symtab_and_line> instead. This avoids introducing heap allocations. gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * ax-gdb.c (agent_command_1): Use range-for. * break-catch-throw.c (re_set_exception_catchpoint): Update. * breakpoint.c: Include "common/array-view.h". (init_breakpoint_sal, create_breakpoint_sal): Change sals parameter from struct symtabs_and_lines to array_view<symtab_and_line>. Adjust. Use range-for. Update. (breakpoint_sals_to_pc): Change sals parameter from struct symtabs_and_lines to std::vector reference. (check_fast_tracepoint_sals): Change sals parameter from struct symtabs_and_lines to std::array_view. Use range-for. (decode_static_tracepoint_spec): Return a std::vector instead of symtabs_and_lines. Update. (create_breakpoint): Update. (break_range_command, until_break_command, clear_command): Update. (base_breakpoint_decode_location, bkpt_decode_location) (bkpt_probe_create_sals_from_location) (bkpt_probe_decode_location, tracepoint_decode_location) (tracepoint_probe_decode_location) (strace_marker_create_sals_from_location): Return a std::vector instead of symtabs_and_lines. (strace_marker_create_breakpoints_sal): Update. (strace_marker_decode_location): Return a std::vector instead of symtabs_and_lines. Update. (update_breakpoint_locations): Change struct symtabs_and_lines parameters to gdb::array_view. Adjust. (location_to_sals): Return a std::vector instead of symtabs_and_lines. Update. (breakpoint_re_set_default): Use std::vector instead of struct symtabs_and_lines. (decode_location_default): Return a std::vector instead of symtabs_and_lines. Update. * breakpoint.h: Include "common/array-view.h". (struct breakpoint_ops) <decode_location>: Now returns a std::vector instead of returning a symtabs_and_lines via output parameter. (update_breakpoint_locations): Change sals parameters to use gdb::array_view. * cli/cli-cmds.c (edit_command, list_command): Update to use std::vector and gdb::array_view. (ambiguous_line_spec): Adjust to use gdb::array_view and range-for. (compare_symtabs): Rename to ... (cmp_symtabs): ... this. Change parameters to symtab_and_line const reference and adjust. (filter_sals): Rewrite using std::vector and standard algorithms. * elfread.c (elf_gnu_ifunc_resolver_return_stop): Simplify. (jump_command): Update to use std::vector. * linespec.c (struct linespec_state) <canonical_names>: Update comment. (add_sal_to_sals_basic): Delete. (add_sal_to_sals, filter_results, convert_results_to_lsals) (decode_line_2, create_sals_line_offset) (convert_address_location_to_sals, convert_linespec_to_sals) (convert_explicit_location_to_sals, parse_linespec) (event_location_to_sals, decode_line_full, decode_line_1) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc) (decode_digits_list_mode, decode_digits_ordinary, minsym_found) (linespec_result::~linespec_result): Adjust to use std::vector instead of symtabs_and_lines. * linespec.h (linespec_sals::sals): Now a std::vector. (struct linespec_result): Use std::vector, bool, and in-class initialization. (decode_line_1, decode_line_with_current_source) (decode_line_with_last_displayed): Return std::vector. * macrocmd.c (info_macros_command): Use std::vector. * mi/mi-main.c (mi_cmd_trace_find): Use std::vector. * probe.c (parse_probes_in_pspace, parse_probes): Adjust to use std::vector. * probe.h (parse_probes): Return a std::vector. * python/python.c (gdbpy_decode_line): Use std::vector and gdb::array_view. * source.c (select_source_symtab, line_info): Use std::vector. * stack.c (func_command): Use std::vector. * symtab.h (struct symtabs_and_lines): Delete. * tracepoint.c (tfind_line_command, scope_info): Use std::vector.
2017-09-04Clarify "list" output when specified lines are ambiguousPedro Alves1-7/+30
Currently, with "list LINESPEC1,LINESPEC2", if one of the linespecs is ambiguous, i.e., if it expands to multiple locations, you get this seemingly odd output: (gdb) list foo,bar file: "file0.c", line number: 26 file: "file1.c", line number: 29 Since "foo" above expands to multiple locations, the specified range is indeterminate, and GDB is trying to be helpful by showing you what was ambiguous. It looks confusing to me, though. I think it'd be much more user friendly if GDB actually told you that, like this: (gdb) list foo,bar Specified first line 'foo' is ambiguous: file: "file0.c", line number: 26 file: "file1.c", line number: 29 (gdb) list bar,foo Specified last line 'foo' is ambiguous: file: "file0.c", line number: 26 file: "file1.c", line number: 29 Note, I'm using "first" and "last" in the output because that's what the manual uses: ~~~ list first,last Print lines from first to last. [...] ~~~ Tested on x86-64 GNU/Linux. gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (edit_command): Pass message to ambiguous_line_spec. (list_command): Pass message to ambiguous_line_spec. Say "first"/"last" instead of "start" and "end" to be consistent with the manual. (ambiguous_line_spec): Add 'format' and vararg parameters. Use them to print formatted message. gdb/testsuite/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * gdb.base/list-ambiguous.exp: New file. * gdb.base/list-ambiguous0.c: New file. * gdb.base/list-ambiguous1.c: New file. * gdb.base/list.exp (test_list_range): Adjust expected output.
2017-09-03Use std::string in do_set_commandTom Tromey1-12/+4
Change do_set_command to use std::string, removing a cleanup and some manual resizing code. ChangeLog 2017-09-03 Tom Tromey <tom@tromey.com> * cli/cli-setshow.c (do_set_command): Use std::string.
2017-09-03Use unique_xmalloc_ptr in cd_commandTom Tromey1-11/+9
Change cd_command to use unique_xmalloc_ptr, removing a cleanup. ChangeLog 2017-09-03 Tom Tromey <tom@tromey.com> * cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr.
2017-08-28define_command: Don't convert command name to lower caseSimon Marchi1-6/+0
Commit Command names: make them case sensitive 3d7b173c29900879c9a5958dd6029fd36666e57c made command name lookup case sensitive. However, define_command, used when creating a user-defined command, converts the command name to lowercase, assuming that the command name lookup works in a case insensitive way. This causes user-defined commands with capital letters in their name to only be callable with a lowercase version: (gdb) define Foo Type commands for definition of "Foo". End with a line saying just "end". >print 1 >end (gdb) Foo Undefined command: "Foo". Try "help". (gdb) foo $1 = 1 This patch removes that conversion to lowercase, so that the user can call the command with the same name they provided. gdb/ChangeLog: * cli/cli-script.c (define_command): Don't convert command name to lower case. gdb/testsuite/ChangeLog: * gdb.base/commands.exp (user_defined_command_case_sensitivity): New proc, call it from toplevel.
2017-08-22List actual code around more than one locationZhouyi Zhou1-16/+31
With the following C++ code: int bar() { return 0;} int bar(int) { return 0; } GDB behaves as: (gdb) list bar file: "overload.cc", line number: 1 file: "overload.cc", line number: 2 It would be better for GDB to list the actual code around those two locations, not just print the location. Like: (gdb) list bar file: "overload.cc", line number: 1 1 int bar() { return 0;} 2 int bar(int) { return 0; } file: "overload.cc", line number: 2 1 int bar() { return 0;} 2 int bar(int) { return 0; } That's what this this commit implements. Tested on x86-64 GNU/Linux. gdb/ChangeLog: 2017-08-22 Zhouyi Zhou <zhouzhouyi@gmail.com> * cli-cmds.c (list_commands): List actual code around more than one location.
2017-08-17Plug source_command leakPedro Alves1-1/+0
The heap-allocated 'old_source_verbose' local was accidentally left behind by commit 2ec845e75876 ("More uses of scoped_restore"). Valgrind caught it, like: ==20123== 8 bytes in 1 blocks are definitely lost in loss record 4,609 of 13,785 ==20123== at 0x4C2A988: calloc (vg_replace_malloc.c:711) ==20123== by 0x60A2F8: xcalloc (common-utils.c:84) ==20123== by 0x4CDBE5: build_command_line(command_control_type, char const*) (cli-script.c:159) ==20123== by 0x4CDC32: get_command_line(command_control_type, char const*) (cli-script.c:172) ==20123== by 0x5230F1: python_command(char*, int) (python.c:421) ==20123== by 0x4C61AD: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:106) ==20123== by 0x4C911F: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1902) ==20123== by 0x7CA79E: execute_command(char*, int) (top.c:650) ==20123== by 0x695A0C: command_handler(char*) (event-top.c:590) ==20123== by 0x7CA33F: read_command_file(_IO_FILE*) (top.c:461) ==20123== by 0x4D0C3A: script_from_file(_IO_FILE*, char const*) (cli-script.c:1584) ==20123== by 0x4C2727: source_script_from_stream(_IO_FILE*, char const*, char const*) (cli-cmds.c:589) gdb/ChangeLog: 2017-08-17 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (source_command): Delete 'old_source_verbose' local.
2017-08-05Use gdb::unique_xmalloc_ptr when calling tilde_expandTom Tromey2-66/+29
This patch changes most sites calling tilde_expand to use gdb::unique_xmalloc_ptr, rather than a cleanup. It also changes scan_expression_with_cleanup to return a unique pointer, because the patch was already touching code in that area. Regression tested on the buildbot. ChangeLog 2017-08-05 Tom Tromey <tom@tromey.com> * compile/compile-object-load.c (compile_object_load): Use gdb::unique_xmalloc_ptr. * cli/cli-dump.c (scan_filename): Rename from scan_filename_with_cleanup. Change return type. (scan_expression): Rename from scan_expression_with_cleanup. Change return type. (dump_memory_to_file, dump_value_to_file, restore_command): Use gdb::unique_xmalloc_ptr. Update. * cli/cli-cmds.c (find_and_open_script): Use gdb::unique_xmalloc_ptr. * tracefile-tfile.c (tfile_open): Use gdb::unique_xmalloc_ptr. * symmisc.c (maintenance_print_symbols) (maintenance_print_msymbols): Use gdb::unique_xmalloc_ptr. * symfile.c (symfile_bfd_open, generic_load) (add_symbol_file_command, remove_symbol_file_command): Use gdb::unique_xmalloc_ptr. * source.c (openp): Use gdb::unique_xmalloc_ptr. * psymtab.c (maintenance_print_psymbols): Use gdb::unique_xmalloc_ptr. * corelow.c (core_open): Use gdb::unique_xmalloc_ptr. * breakpoint.c (save_breakpoints): Use gdb::unique_xmalloc_ptr. * solib.c (solib_map_sections): Use gdb::unique_xmalloc_ptr. (reload_shared_libraries_1): Likewise.
2017-08-03Introduce gdb_argv, a class wrapper for buildargvTom Tromey1-18/+13
This introduces gdb_argv, a class wrapping an "argv" pointer; that is, a pointer to a NULL-terminated array of char*, where both the array and each non-NULL element in the array are xmalloc'd. This patch then changes most users of gdb_buildargv to use gdb_argv instead. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * utils.h (struct gdb_argv_deleter): New. (gdb_argv): New class. * utils.c (gdb_argv::reset): New method. * tracepoint.c (delete_trace_variable_command): Use gdb_argv. * tracefile.c (tsave_command): Use gdb_argv. * top.c (new_ui_command): Use gdb_argv. * symmisc.c (maintenance_print_symbols) (maintenance_print_msymbols, maintenance_expand_symtabs): Use gdb_argv. * symfile.c (symbol_file_command, generic_load) (remove_symbol_file_command): Use gdb_argv. * stack.c (backtrace_command): Use gdb_argv. * source.c (add_path, show_substitute_path_command) (unset_substitute_path_command, set_substitute_path_command): Use gdb_argv. * skip.c (skip_command): Use gdb_argv. Use gdb_buildargv. * ser-mingw.c (pipe_windows_open): Use gdb_argv. * remote.c (extended_remote_run, remote_put_command) (remote_get_command, remote_delete_command): Use gdb_argv. * remote-sim.c (gdbsim_load, gdbsim_create_inferior) (gdbsim_open): Use gdb_argv. * python/py-cmd.c (gdbpy_string_to_argv): Use gdb_argv. * psymtab.c (maintenance_print_psymbols): Use gdb_argv. * procfs.c (procfs_info_proc): Use gdb_argv. * interps.c (interpreter_exec_cmd): Use gdb_argv. * infrun.c (handle_command): Use gdb_argv. * inferior.c (add_inferior_command, clone_inferior_command): Use gdb_argv. * guile/scm-string.c (gdbscm_string_to_argv): Use gdb_argv. * exec.c (exec_file_command): Use gdb_argv. * cli/cli-cmds.c (alias_command): Use gdb_argv. * compile/compile.c (build_argc_argv): Use gdb_argv.
2017-08-03Replace do_restore_instream_cleanup with scoped_restoreTom Tromey1-4/+2
This changes the users of do_restore_instream_cleanup to use a scoped_restore instead. This patch is broken out because it warrants some additional attention: in particular it's unclear to me whether current_ui can change in the body of these functions -- but if it can, then the cleanup would have modified a different UI's instream member. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * top.h (do_restore_instream_cleanup): Remove. * top.c (do_restore_instream_cleanup): Remove. (read_command_file): Use scoped_restore. * cli/cli-script.c (execute_user_command): Use scoped_restore.
2017-08-03Use a scoped_restore for command_nest_depthTom Tromey1-6/+6
This changes a couple of places to use a scoped_restore when manipulating command_nest_depth. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * cli/cli-script.c (execute_user_command) (execute_control_command): Use scoped_restore.
2017-08-03Remove user_call_depthTom Tromey1-15/+2
This changes execute_user_command to remove user_call_depth, using the size of user_args_stack instead. This avoids a cleanup. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * cli/cli-script.c (do_restore_user_call_depth): Remove. (execute_user_command): Remove user_call_depth; use user_args_stack's size instead.
2017-08-03Remove in_user_commandTom Tromey1-6/+0
While working on the next patch in this series, I found that the global in_user_command is not used. This patch removes it. (I didn't think to check Insight until submitting this series; and it's not very convenient to do so, so if someone has it checked out and could look at it, that would be nice.) ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * top.h (in_user_command): Remove. * top.c (in_user_command): Remove. * cli/cli-script.c (do_restore_user_call_depth) (execute_user_command): Update.
2017-08-03Use containers to avoid cleanupsTom Tromey1-8/+3
This patch introduces the use of various containers -- std::vector, std::string, or gdb::byte_vector -- in several spots in gdb that were using xmalloc and a cleanup. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * valops.c (search_struct_method): Use gdb::byte_vector. * valarith.c (value_concat): Use std::vector. * target.c (memory_xfer_partial): Use gdb::byte_vector. (simple_search_memory): Likewise. * printcmd.c (find_string_backward): Use gdb::byte_vector. * mi/mi-main.c (mi_cmd_data_write_memory): Use gdb::byte_vector. * gcore.c (gcore_copy_callback): Use gdb::byte_vector. * elfread.c (elf_rel_plt_read): Use std::string. * cp-valprint.c (cp_print_value): Use gdb::byte_vector. * cli/cli-dump.c (restore_section_callback): Use gdb::byte_vector.
2017-08-03More uses of scoped_restoreTom Tromey2-57/+19
There were a few more places in gdb that could easily use scoped_restore, replacing some cleanups. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * reverse.c (exec_direction_default): Remove. (exec_reverse_once): Use scoped_restore. * remote.c (restore_remote_timeout): Remove. (remote_flash_erase, remote_flash_write, remote_flash_done) (readchar, remote_serial_write): Use scoped_restore. * cli/cli-script.c (struct source_cleanup_lines_args) (source_cleanup_lines): Remove. (script_from_file): Use scoped_restore. * cli/cli-cmds.c (source_verbose_cleanup): Remove. (source_command): Use scoped_restore.
2017-08-03Change return type of find_and_open_scriptTom Tromey2-24/+37
This changes find_and_open_script to return a gdb::optional<open_script>, where open_script is a new type encapsulating the two return values. The new type helps avoid cleanups in the callers. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * cli/cli-cmds.c (find_and_open_script): Change return type. Remove "streamp" and "full_path" parameters. (source_script_with_search): Update. * auto-load.c (source_script_file): Update. * cli/cli-cmds.h (find_and_open_script): Change type. (open_script): New struct.
2017-08-03Introduce and use gdb_file_upTom Tromey1-21/+7
This introduces gdb_file_up, a unique pointer holding a FILE*, and then changes some code in gdb to use it. In particular gdb_fopen_cloexec now returns a gdb_file_up. This allow removing some cleanups. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * xml-support.c (xml_fetch_content_from_file): Update. * ui-file.c (stdio_file::open): Update. * tracefile-tfile.c (tfile_start): Update. * remote.c (remote_file_put, remote_file_get): Update. * nat/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_get_state, linux_proc_tid_get_name): Update. * nat/linux-osdata.c (linux_common_core_of_thread): Update. (command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus) (print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update. * nat/linux-btrace.c (linux_determine_kernel_start): Update. * linux-nat.c (linux_proc_pending_signals): Update. * dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up. (file_closer): Remove. * compile/compile.c (compile_to_object): Update. * common/filestuff.h (struct gdb_file_deleter): New. (gdb_file_up): New typedef. (gdb_fopen_cloexec): Change return type. * common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up. * cli/cli-dump.c (fopen_with_cleanup): Remove. (dump_binary_file, restore_binary_file): Update. * auto-load.c (auto_load_objfile_script_1): Update.
2017-07-26Add "maint check xml-descriptions" to test builtin xml target descriptionsYao Qi1-0/+4
Now, GDB is able to dynamically create i386-linux target descriptions from features, instead of using pre-generated target descriptions. These pre-generated target descriptions are no longer used by GDB (note that they are still used by GDBserver). This patch add a new maint command "maint check xml-descriptions" to test dynamically generated tdesc are identical to these generated from xml files. gdb: 2017-07-26 Yao Qi <yao.qi@linaro.org> * cli/cli-cmds.c (maintenancechecklist): New variable. * gdbcmd.h (maintenancechecklist): Declare it. * i386-linux-tdep.c (_initialize_i386_linux_tdep) [GDB_SELF_TEST]: Call i386_linux_read_description with different masks. * maint.c (maintenance_check_command): New function. (_initialize_maint_cmds): Call add_prefix_cmd. * target-descriptions.c (tdesc_reg): override operator != and ==. (tdesc_type): Likewise. (tdesc_feature): Likewise. (target_desc): Likewise. [GDB_SELF_TEST] (selftests::record_xml_tdesc): New function. (maintenance_check_xml_descriptions): New function. (_initialize_target_descriptions) Add command "xml-descriptions". * target-descriptions.h (selftests::record_xml_tdesc): Declare. gdb/testsuite: 2017-07-26 Yao Qi <yao.qi@linaro.org> * gdb.gdb/unittest.exp: Invoke command "maintenance check xml-descriptions". gdb/doc: 2017-07-26 Yao Qi <yao.qi@linaro.org> * gdb.texinfo (Maintenance Commands): Document command "maint check xml-descriptions".
2017-07-17Rewrite/enhance explicit locations completer, parse left->rightPedro Alves1-4/+13
One of the most annoying (to me) things about GDB's completion is when you have overloads in your program, and you want to set a breakpoint in one of them: void function(int); // set breakpoint here. void function(long); (gdb) b -f func[TAB] (gdb) b -f function( # ok, gdb completed as much as possible. (gdb) b -f function([TAB] # show me the overloads, please. <_all_ symbols in the program are shown...> E.g., when debugging GDB, that'd be: (gdb) b -f function([TAB] (anonymous namespace)::get_global()::global pt_insn_get_offset@plt scm_new_port_table_entry asprintf pt_pkt_alloc_decoder scm_new_port_table_entry@plt asprintf@plt pt_pkt_alloc_decoder@plt scm_out_of_range bt_ctf_get_char_array pt_pkt_sync_forward scm_out_of_range@plt bt_ctf_get_char_array@plt pt_pkt_sync_forward@plt scm_putc bt_ctf_get_uint64 pwrite scm_putc@plt bt_ctf_get_uint64@plt pwrite@plt scm_reverse_x bt_ctf_iter_read_event PyErr_Restore scm_reverse_x@plt bt_ctf_iter_read_event@plt PyErr_Restore@plt scm_set_port_filename_x <snip...> Now that's a load of completely useless completions. The reason GDB offers those is that the completer relies on readline figuring out the completion word point in the input line based on the language's word break characters, which include "(". So readline tells the completer to complete on "", the string that is after '('. Likewise, if you type "function(i[TAB]" to try to complete to "int", you're out of luck. GDB shows you all the symbols in the program that start with "i"... This makes sense for the expression completer, as what you'd want to type is e.g., a global variable, say: (gdb) print function(i[TAB] but, it makes no sense when specifying a function name for a breakpoint location. To get around that limitation, users need to quote the function name, like: (gdb) b -f 'function([TAB] function(int) function(long) (gdb) b 'function(i[TAB] (gdb) b 'function(int)' # now completes correctly! Note that the quoting is only necessary for completion. Creating the breakpoint does not require the quoting: (gdb) b -f function(int) [RET] Breakpoint 1 at .... This patch removes this limitation. ( Actually, it's a necessary patch, though not sufficient. That'll start working correctly by the end of the series. With this patch, if try it, you'll see: (gdb) b -f function(i[TAB] (gdb) b -f function i.e., gdb strips everything after the "(". That's caused by some code in symtab.c that'll be eliminated further down the series. These patches are all unfortunately interrelated, which is also the reason new tests only appear much later in the series. But let's ignore that reality for the remainder of the description. ) So... this patch gets rid of the need for quoting. It does that by adding a way for a completer to control the exact completion word point that readline should start the completion request for, instead of letting readline try to figure it out using the current language's word break chars array, and often failing. In the case above, we want the completer to figure out that it's completing a function name that starts with "function(i". It now does. It took me a while to figure out a way to ask readline to "use this exact word point", and for a while I feared that it'd be impossible with current readline (and having to rely on master readline for core functionality is something I'd like to avoid very much). Eventually, after several different attempts, I came up with what is described in the comment above gdb_custom_word_point_brkchars in the patch. With this patch, the handle_brkchars phase of the explicit location completer advances the expected word point as it parses the input line left to right, until it figures out exactly what we're completing, instead of expecting readline to break the string using the word break characters, and then having the completer heuristically fix up a bad decision by parsing the input string backwards. This allows correctly knowning that we're completing a symbol name after -function, complete functions without quoting, etc. Later, we'll make use of this same mechanims to implement a proper linespec completer that avoids need for quoting too. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * cli/cli-cmds.c (complete_command): Get the completion result out of the handle_brkchars tracker if used a custom word point. * completer.c: Include "linespec.h". (enum explicit_location_match_type) <MATCH_LINE>: New enumerator. (advance_to_expression_complete_word_point): New. (completion_tracker::completes_to_completion_word): New. (complete_files_symbols): Pass down complete_symbol_mode::EXPRESSION. (explicit_options, probe_options): New. (collect_explicit_location_matches): Complete on the explictit_loc->foo instead of word. Use linespec_complete_function. Handle MATCH_LINE. Handle offering keyword and options completions. (backup_text_ptr): Delete. (skip_keyword): New. (complete_explicit_location): Remove 'word' parameter. Add language, quoted_arg_start and quoted_arg_end parameters. Rewrite, parsing left to right. (location_completer): Rewrite. (location_completer_handle_brkchars): New function. (symbol_completer): Pass down complete_symbol_mode::EXPRESSION. (enum complete_line_internal_reason): Adjust comments. (completion_tracker::discard_completions): New. (completer_handle_brkchars_func_for_completer): Handle location_completer. (gdb_custom_word_point_brkchars) (gdb_org_rl_basic_quote_characters): New. (gdb_completion_word_break_characters_throw) (completion_find_completion_word): Handle trackers that use a custom word point. (completion_tracker::advance_custom_word_point_by): New. (completion_tracker::build_completion_result): Don't rely on readline appending the quote char. (gdb_rl_attempted_completion_function_throw): Handle trackers that use a custom word point. (gdb_rl_attempted_completion_function): Restore rl_basic_quote_characters. * completer.h (class completion_tracker): Extend intro comment. (completion_tracker::set_quote_char) (completion_tracker::quote_char) (completion_tracker::set_use_custom_word_point) (completion_tracker::use_custom_word_point) (completion_tracker::custom_word_point) (completion_tracker::set_custom_word_point) (completion_tracker::advance_custom_word_point_by) (completion_tracker::completes_to_completion_word) (completion_tracker::discard_completions): New methods. (completion_tracker::m_quote_char) (completion_tracker::m_use_custom_word_point) (completion_tracker::m_custom_word_point): New fields. (advance_to_expression_complete_word_point): Declare. * f-lang.c (f_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * language.h (struct language_defn) <la_collect_symbol_completion_matches>: Add complete_symbol_mode parameter. * linespec.c (linespec_keywords): Add NULL terminator. Make extern. (linespec_complete_function): New function. (linespec_lexer_lex_keyword): Adjust. * linespec.h (linespec_keywords, linespec_complete_function): New declarations. * location.c (find_end_quote): New function. (explicit_location_lex_one): Add explicit_completion_info parameter. Save quoting info. Don't throw if being called for completion. Don't handle Ada operators here. (is_cp_operator, skip_op_false_positives, first_of) (explicit_location_lex_one_function): New function. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. Handle it. Don't use explicit_location_lex_one to lex function names. Use explicit_location_lex_one_function instead. * location.h (struct explicit_completion_info): New. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. * symtab.c (default_collect_symbol_completion_matches_break_on): Add complete_symbol_mode parameter. Handle LINESPEC mode. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add complete_symbol_mode parameter. (collect_symbol_completion_matches_type): Pass down complete_symbol_mode::EXPRESSION. (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. Handle LINESPEC mode. * symtab.h (complete_symbol_mode): New. (default_collect_symbol_completion_matches_break_on) (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. gdb/testsuite/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17"complete" command and completion word break charactersPedro Alves1-19/+15
The linespec/locations/completer testcase added later in the series tests every completion with both TAB completion and the "complete" command. This exposed problems in the "complete" command, around determining the completion word point. First, the complete command has a too-simple approximation of what readline's TAB-completion code does to find the completion word point. Unfortunately, readline doesn't expose the functionality it uses internally, so to fix this this patch copies over the relevant code, and adjusts it a bit to better fit the use cases we need it for. (Specifically, our version avoids relying on the rl_word_break_characters, etc. globals, and instead takes those as arguments.) A following patch will want to use this function for TAB-completion too, but the "complete" command was a good excuse to split this to a separate patch. Then, notice how the complete_command does not call into the completer for the command being completed to determine the right set of word break characters. It always uses the default set. That is fixed by having the "complete" command call into complete_line_internal for a full handle_brkchars phase, just TAB-completion. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (complete_command): Use a completion tracker along with completion_find_completion_word for handle_brkchars phase. * completer.c (RL_QF_SINGLE_QUOTE, RL_QF_DOUBLE_QUOTE) (RL_QF_BACKSLASH, RL_QF_OTHER_QUOTE): New. (struct gdb_rl_completion_word_info): New. (gdb_rl_find_completion_word): New. (completion_find_completion_word): New. * completer.h (completion_find_completion_word): Declare.
2017-07-17Introduce class completion_tracker & rewrite completion<->readline interactionPedro Alves2-42/+47
This patch reworks the whole completion machinery, and prepares it for later enhancements. Adds a new "completion_tracker" class that is meant to hold everything about the state of the current completion operation. This class now has the responsibility of tracking the list of completion matches, and checking whether the max completions limit has been reached. You can look at this as this patch starting out by C++fying the existing "completion_tracker" in symtab.c (it's just an htab_t typedef currently), moving it to completer.h/c, and then making it a class/generalizing/enhancing it. Unlike with the current tracking, completion_tracker now checks whether the limit has been reached on each completion match list insertion. This both simplifies the max-completions handling code (maybe_add_completion_enum is gone, for example), and is a prerequisite for follow up patches. The current completion_tracker is only used for symbol completions, and the symbol code gets at the current instance via globals. This patch cleans that up by adding a completion_tracker reference to the signature of the completion functions, and passing the tracker around everywhere necessary. Then, the patch changes how the completion match list is handed over to readline. Currently, we're using the rl_completion_entry_function readline entry point, and the patch switches to rl_attempted_completion_function. A following patch will want to let GDB itself decide the common completion prefix between all matches (what readline calls the "lowest common denominator"), instead of having readline compute it, and that's not possible with the rl_completion_entry_function entry point. Also, rl_attempted_completion_function lets GDB hand over the match list to readline as an array in one go instead of passing down matches one by one, so from that angle it's a nicer entry point anyway. Lastly, the patch catches exceptions around the readline entry points, because we can't let C++ exceptions cross readline. We handle that in the readline input entry point, but the completion entry point isn't guarded, so GDB can abort if completion throws. E.g., in current master: (gdb) b -function "fun<tab> terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR' Aborted (core dumped) This patch fixes that. This will be exercised in the new tests added later on in the series. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * ada-lang.c (symbol_completion_match): Adjust comments. (symbol_completion_add): Replace vector parameter with completion_tracker parameter. Use it. (ada_make_symbol_completion_list): Rename to... (ada_collect_symbol_completion_matches): ... this. Add completion_tracker parameter and use it. (ada_language_defn): Adjust. * break-catch-syscall.c (catch_syscall_completer): Adjust prototype and work with completion_tracker instead of VEC. * breakpoint.c (condition_completer): Adjust prototype and work with completion_tracker instead of VEC. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust to renames. * cli/cli-cmds.c (complete_command): Rework using completion_tracker. Catch exceptions when completing. * cli/cli-decode.c (integer_unlimited_completer) (complete_on_cmdlist, complete_on_enum): Adjust prototype and work with completion_tracker instead of VEC. * command.h (struct completion_tracker): Forward declare. (completer_ftype, completer_handle_brkchars_ftype): Change types. (complete_on_cmdlist, complete_on_enum): Adjust. * completer.c: Include <algorithm>. (struct gdb_completer_state): New. (current_completion): New global. (readline_line_completion_function): Delete. (noop_completer, filename_completer) (filename_completer_handle_brkchars, complete_files_symbols) (linespec_location_completer): Adjust to work with a completion_tracker instead of a VEC. (string_or_empty): New. (collect_explicit_location_matches): Adjust to work with a completion_tracker instead of a VEC. (explicit_location_completer): Rename to ... (complete_explicit_location): ... this and adjust to work with a completion_tracker instead of a VEC. (location_completer): Adjust to work with a completion_tracker instead of a VEC. (add_struct_fields): Adjust to work with a completion_list instead of VEC. (expression_completer): Rename to ... (complete_expression): ... this and adjust to work with a completion_tracker instead of a VEC. Use complete_files_symbols. (expression_completer): Reimplement on top of complete_expression. (symbol_completer): Adjust to work with a completion_tracker instead of a VEC. (enum complete_line_internal_reason): Add describing comments. (complete_line_internal_normal_command): Adjust to work with a completion_tracker instead of a VEC. (complete_line_internal): Rename to ... (complete_line_internal_1): ... this and adjust to work with a completion_tracker instead of a VEC. Assert TEXT is NULL in the handle_brkchars phase. (new_completion_tracker): Delete. (complete_line_internal): Reimplement as TRY/CATCH wrapper around complete_line_internal_1. (free_completion_tracker): Delete. (INITIAL_COMPLETION_HTAB_SIZE): New. (completion_tracker::completion_tracker) (completion_tracker::~completion_tracker): New. (maybe_add_completion): Delete. (completion_tracker::maybe_add_completion) (completion_tracker::add_completion) (completion_tracker::add_completions): New. (throw_max_completions_reached_error): Delete. (complete_line): Adjust to work with a completion_tracker instead of a VEC. Don't create a completion_tracker_t or check for max completions here. (command_completer, command_completer_handle_brkchars) (signal_completer, reg_or_group_completer_1) (reg_or_group_completer, default_completer_handle_brkchars): Adjust to work with a completion_tracker. (gdb_completion_word_break_characters_throw): New. (gdb_completion_word_break_characters): Reimplement. (line_completion_function): Delete. (completion_tracker::recompute_lowest_common_denominator) (expand_preserving_ws) (completion_tracker::build_completion_result) (completion_result::completion_result) (completion_result::completion_result) (completion_result::~completion_result) (completion_result::completion_result) (completion_result::release_match_list, compare_cstrings) (completion_result::sort_match_list) (completion_result::reset_match_list) (gdb_rl_attempted_completion_function_throw) (gdb_rl_attempted_completion_function): New. * completer.h (completion_list, struct completion_result) (class completion_tracker): New. (complete_line): Add completion_tracker parameter. (readline_line_completion_function): Delete. (gdb_rl_attempted_completion_function): New. (noop_completer, filename_completer, expression_completer) (location_completer, symbol_completer, command_completer) (signal_completer, reg_or_group_completer): Update prototypes. (completion_tracker_t, new_completion_tracker) (make_cleanup_free_completion_tracker): Delete. (enum maybe_add_completion_enum): Delete. (maybe_add_completion): Delete. (throw_max_completions_reached_error): Delete. * corefile.c (complete_set_gnutarget): Adjust to work with a completion_tracker instead of a VEC. * cp-abi.c (cp_abi_completer): Adjust to work with a completion_tracker instead of a VEC. * d-lang.c (d_language_defn): Adjust. * disasm.c (disassembler_options_completer): Adjust to work with a completion_tracker instead of a VEC. * f-lang.c (f_make_symbol_completion_list): Rename to ... (f_collect_symbol_completion_matches): ... this. Adjust to work with a completion_tracker instead of a VEC. (f_language_defn): Adjust. * go-lang.c (go_language_defn): Adjust. * guile/scm-cmd.c (cmdscm_add_completion, cmdscm_completer): Adjust to work with a completion_tracker instead of a VEC. * infrun.c (handle_completer): Likewise. * interps.c (interpreter_completer): Likewise. * interps.h (interpreter_completer): Likewise. * language.c (unknown_language_defn, auto_language_defn) (local_language_defn): Adjust. * language.h (language_defn::la_make_symbol_completion_list): Rename to ... (language_defn::la_collect_symbol_completion_matches): ... this and adjust to work with a completion_tracker instead of a VEC. * m2-lang.c (m2_language_defn): Adjust. * objc-lang.c (objc_language_defn): Adjust. * opencl-lang.c (opencl_language_defn): Adjust. * p-lang.c (pascal_language_defn): Adjust. * python/py-cmd.c (cmdpy_completer_helper): Handle NULL word. (cmdpy_completer_handle_brkchars, cmdpy_completer): Adjust to work with a completion_tracker. * rust-lang.c (rust_language_defn): Adjust. * symtab.c (free_completion_list, do_free_completion_list) (return_val, completion_tracker): Delete. (completion_list_add_name, completion_list_add_symbol) (completion_list_add_msymbol, completion_list_objc_symbol) (completion_list_add_fields, add_symtab_completions): Add completion_tracker parameter and use it. (default_make_symbol_completion_list_break_on_1): Rename to... (default_collect_symbol_completion_matches_break_on): ... this. Add completion_tracker parameter and use it instead of allocating a completion tracker here. (default_make_symbol_completion_list_break_on): Delete old implementation. (default_make_symbol_completion_list): Delete. (default_collect_symbol_completion_matches): New. (make_symbol_completion_list): Delete. (collect_symbol_completion_matches): New. (make_symbol_completion_type): Rename to ... (collect_symbol_completion_matches_type): ... this. Add completion_tracker parameter and use it instead of VEC. (make_file_symbol_completion_list_1): Rename to... (collect_file_symbol_completion_matches): ... this. Add completion_tracker parameter and use it instead of VEC. (make_file_symbol_completion_list): Delete. (add_filename_to_list): Use completion_list instead of a VEC. (add_partial_filename_data::list): Now a completion_list. (make_source_files_completion_list): Work with a completion_list instead of a VEC. * symtab.h: Include "completer.h". (default_make_symbol_completion_list_break_on) (default_make_symbol_completion_list, make_symbol_completion_list) (make_symbol_completion_type, make_file_symbol_completion_list) (make_source_files_completion_list): Delete. (default_collect_symbol_completion_matches_break_on) (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_symbol_completion_matches_type) (collect_file_symbol_completion_matches) (make_source_files_completion_list): New. * top.c (init_main): Don't install a rl_completion_entry_function hook. Install a rl_attempted_completion_function hook instead. * tui/tui-layout.c (layout_completer): Adjust to work with a completion_tracker. * tui/tui-regs.c (tui_reggroup_completer): * tui/tui-win.c (window_name_completer, focus_completer) (winheight_completer): Adjust to work with a completion_tracker. * value.c: Include "completer.h". (complete_internalvar): Adjust to work with a completion_tracker. * value.h (complete_internalvar): Likewise.
2017-07-17Clean up "completer_handle_brkchars" callback handlingPedro Alves2-17/+4
This patch cleans up "completer_handle_brkchars" callback handling: - Renames the function typedef to better match its intent: completer_ftype_void -> completer_handle_brkchars_ftype - Factors out common code in complete_line_internal handling the "handle_brkchars" callback to a separate function. - Centralizes all the "completer method" to "handle_brkchars method" mapping in a single function. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * cli/cli-decode.c (set_cmd_completer_handle_brkchars): Adjust to renames. * cli/cli-decode.h (struct cmd_list_element) <completer>: Move comments to completer_ftype's declaration. <completer_handle_brkchars>: Change type to completer_handle_brkchars_ftype. * command.h (completer_ftype): Add describing comment and give names to parameters. (completer_ftype_void): Rename to ... (completer_handle_brkchars_ftype) ... this. Add describing comment. (set_cmd_completer_handle_brkchars): Adjust. * completer.c (filename_completer_handle_brkchars): New function. (complete_line_internal_normal_command): New function, factored out from ... (complete_line_internal): ... here. (command_completer_handle_brkchars) (default_completer_handle_brkchars) (completer_handle_brkchars_func_for_completer): New functions. * completer.h (set_gdb_completion_word_break_characters): Delete declaration. (completer_handle_brkchars_func_for_completer): New declaration. * python/py-cmd.c (cmdpy_completer_handle_brkchars): Adjust to use completer_handle_brkchars_func_for_completer.
2017-07-17Rename make_symbol_completion_list_fn -> symbol_completerPedro Alves1-1/+1
"make_symbol_completion_list_fn" is odly named when you look at a list of "standard" completers, like the Python/Guile completer lists adjusted by this patch. Rename / move it to completers.h/c, for consistency. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * completer.c (symbol_completer): New function, based on make_symbol_completion_list_fn. * completer.h (symbol_completer): New declaration. * guile/scm-cmd.c (cmdscm_completers): Adjust. * python/py-cmd.c (completers): Adjust. * symtab.c (make_symbol_completion_list_fn): Delete. * symtab.h (make_symbol_completion_list_fn): Delete. * cli/cli-decode.c (add_cmd): Adjust.
2017-06-30PR cli/21688: Detect aliases when issuing python/compile/guile commands (and ↵Sergio Durigan Junior1-17/+5
fix last commit) My last commit fixed a regression that happened when using inline/multi-line commands for Python/Compile/Guile, but introduced another regression: it is now not possible to use aliases for the commands mentioned above. The fix is to almost revert the change I've made and go back to using the 'struct cmd_list_element *', but at the same time make sure that we advance the 'cmd_name' variable past all the whitespace characters after the command name. If, after skipping the whitespace, we encounter a '\0', it means that the command is not inline. Otherwise, it is. This patch also expands the testcase in order to check for aliases and for trailing whitespace after the command name. gdb/ChangeLog: 2017-06-30 Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> PR cli/21688 * cli/cli-script.c (command_name_equals_not_inline): Remove function. (process_next_line): New variable 'inline_cmd'. Adjust 'if' clauses for "python", "compile" and "guile" to use 'command_name_equals' and check for '!inline_cmd'. gdb/testsuite/ChangeLog: 2017-06-30 Sergio Durigan Junior <sergiodj@redhat.com> PR cli/21688 * gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add new tests for alias commands and trailing whitespace.
2017-06-30PR cli/21688: Fix multi-line/inline command differentiationSergio Durigan Junior1-4/+17
This bug is a regression caused by the following commit: 604c4576fdcfc4e7c28f569b3748a1b6b4e0dbd4 is the first bad commit commit 604c4576fdcfc4e7c28f569b3748a1b6b4e0dbd4 Author: Jerome Guitton <guitton@adacore.com> Date: Tue Jan 10 15:15:53 2017 +0100 The problem happens because, on cli/cli-script.c:process_next_line, GDB is not using the command line string to identify which command to run, but it instead using the 'struct cmd_list_element *' that is obtained by using the mentioned string. The problem with that is that the 'struct cmd_list_element *' doesn't have any information on whether the command issued by the user is a multi-line or inline one. A multi-line command is a command that will necessarily be composed of more than 1 line. For example: (gdb) if 1 >python >print ('hello') >end >end As can be seen in the example above, the 'python' command actually "opens" a new command line (represented by the change in the indentation) that will then be used to enter Python code. OTOH, an inline command is a command that is "self-contained" in a single line, for example: (gdb) if 1 >python print ('hello') >end This Python command is a one-liner, and therefore there is no other Python code that can be entered for this same block. There is also no change in the indentation. So, the fix is somewhat simple: we have to revert the change and use the full command line string passed to process_next_line in order to identify whether we're dealing with a multi-line or an inline command. This commit does just that. As can be seen, this regression also affects other languages, like guile or the compile framework. To make things clearer, I decided to create a new helper function responsible for identifying a non-inline command. Testcase is attached. gdb/ChangeLog: 2017-06-30 Sergio Durigan Junior <sergiodj@redhat.com> PR cli/21688 * cli/cli-script.c (command_name_equals_not_inline): New function. (process_next_line): Adjust 'if' clauses for "python", "compile" and "guile" to use command_name_equals_not_inline. gdb/testsuite/ChangeLog: 2017-06-30 Sergio Durigan Junior <sergiodj@redhat.com> PR cli/21688 * gdb.python/py-cmd.exp (test_python_inline_or_multiline): New procedure. Call it.
2017-06-14Introduce gdb::byte_vector, add allocator that default-initializesPedro Alves1-8/+8
In some cases we've been replacing heap-allocated gdb_byte buffers managed with xmalloc/make_cleanup(xfree) with gdb::vector<gdb_byte>. That usually pessimizes the code a little bit because std::vector value-initializes elements (which for gdb_byte means zero-initialization), while if you're creating a temporary buffer, you're most certaintly going to fill it in with some data. An alternative is to use unique_ptr<gdb_byte[]> buf (new gdb_byte[size]); but it looks like that's not very popular. Recently, a use of obstacks in dwarf2read.c was replaced with std::vector<gdb_byte> and that as well introduced a pessimization for always memsetting the buffer when it's garanteed that the zeros will be overwritten immediately. (see dwarf2read.c change in this patch to find it.) So here's a different take at addressing this issue "by design": #1 - Introduce default_init_allocator<T> I.e., a custom allocator that does default construction using default initialization, meaning, no more zero initialization. That's the default_init_allocation<T> class added in this patch. See "Notes" at <http://en.cppreference.com/w/cpp/container/vector/resize>. #2 - Introduce def_vector<T> I.e., a convenience typedef, because typing the allocator is annoying: using def_vector<T> = std::vector<T, gdb::default_init_allocator<T>>; #3 - Introduce byte_vector Because gdb_byte vectors will be the common thing, add a convenience "byte_vector" typedef: using byte_vector = def_vector<gdb_byte>; which is really the same as: std::vector<gdb_byte, gdb::default_init_allocator<gdb_byte>>; The intent then is to make "gdb::byte_vector" be the go-to for dynamic byte buffers. So the less friction, the better. #4 - Adjust current code to use it. To set the example going forward. Replace std::vector uses and also unique_ptr<byte[]> uses. One nice thing is that with this allocator, for changes like these: -std::unique_ptr<byte[]> buf (new gdb_byte[some_size]); +gdb::byte_vector buf (some_size); fill_with_data (buf.data (), buf.size ()); the generated code is the same as before. I.e., the compiler de-structures the vector and gets rid of the unused "reserved vs size" related fields. The other nice thing is that it's easier to write gdb::byte_vector buf (size); than std::unique_ptr<gdb_byte[]> buf (new gdb_byte[size]); or even (C++14): auto buf = std::make_unique<gdb_byte[]> (size); // zero-initializes... #5 - Suggest s/std::vector<gdb_byte>/gdb::byte_vector/ going forward. Note that this commit actually fixes a couple of bugs where the current code is incorrectly using "std::vector::reserve(new_size)" and then accessing the vector's internal buffer beyond the vector's size: see dwarf2loc.c and charset.c. That's undefined behavior and may trigger debug mode assertion failures. With default_init_allocator, "resize()" behaves like "reserve()" performance wise, in that it leaves new elements with unspecified values, but, it does that safely without triggering undefined behavior when you access those values. gdb/ChangeLog: 2017-06-14 Pedro Alves <palves@redhat.com> * ada-lang.c: Include "common/byte-vector.h". (ada_value_primitive_packed_val): Use gdb::byte_vector. * charset.c (wchar_iterator::iterate): Resize the vector instead of reserving it. * common/byte-vector.h: Include "common/def-vector.h". (wchar_iterator::m_out): Now a gdb::def_vector<gdb_wchar_t>. * cli/cli-dump.c: Include "common/byte-vector.h". (dump_memory_to_file, restore_binary_file): Use gdb::byte_vector. * common/byte-vector.h: New file. * common/def-vector.h: New file. * common/default-init-alloc.h: New file. * dwarf2loc.c: Include "common/byte-vector.h". (rw_pieced_value): Use gdb::byte_vector, and resize the vector instead of reserving it. * dwarf2read.c: Include "common/byte-vector.h". (data_buf::m_vec): Now a gdb::byte_vector. * gdb_regex.c: Include "common/def-vector.h". (compiled_regex::compiled_regex): Use gdb::def_vector<char>. * mi/mi-main.c: Include "common/byte-vector.h". (mi_cmd_data_read_memory): Use gdb::byte_vector. * printcmd.c: Include "common/byte-vector.h". (print_scalar_formatted): Use gdb::byte_vector. * valprint.c: Include "common/byte-vector.h". (maybe_negate_by_bytes, print_decimal_chars): Use gdb::byte_vector.
2017-06-07Introduce compiled_regex, eliminate make_regfree_cleanupPedro Alves3-25/+12
This patch replaces compile_rx_or_error and make_regfree_cleanup with a class that wraps a regex_t. gdb/ChangeLog: 2017-06-07 Pedro Alves <palves@redhat.com> * Makefile.in (SFILES): Add gdb_regex.c. (COMMON_OBS): Add gdb_regex.o. * ada-lang.c (ada_add_standard_exceptions) (ada_add_exceptions_from_frame, name_matches_regex) (ada_add_global_exceptions, ada_exceptions_list_1): Change regex parameter type to compiled_regex. Adjust. (ada_exceptions_list): Use compiled_regex. * break-catch-throw.c (exception_catchpoint::pattern): Now a std::unique_ptr<compiled_regex>. (exception_catchpoint::~exception_catchpoint): Remove regfree call. (check_status_exception_catchpoint): Adjust to use compiled_regex. (handle_gnu_v3_exceptions): Adjust to use compiled_regex. * breakpoint.c (solib_catchpoint::compiled): Now a std::unique_ptr<compiled_regex>. (solib_catchpoint::~solib_catchpoint): Remove regfree call. (check_status_catch_solib): Adjust to use compiled_regex. (add_solib_catchpoint): Adjust to use compiled_regex. * cli/cli-cmds.c (apropos_command): Use compiled_regex. * cli/cli-decode.c (apropos_cmd): Change regex parameter to compiled_regex reference. Adjust to use it. * cli/cli-decode.h: Remove struct re_pattern_buffer forward declaration. Include "gdb_regex.h". (apropos_cmd): Change regex parameter to compiled_regex reference. * gdb_regex.c: New file. * gdb_regex.h (make_regfree_cleanup, get_regcomp_error): Delete declarations. (class compiled_regex): New. * linux-tdep.c: Include "common/gdb_optional.h". (struct mapping_regexes): New, factored out from mapping_is_anonymous_p, and adjusted to use compiled_regex. (mapping_is_anonymous_p): Use mapping_regexes wrapped in a gdb::optional and remove cleanups. Adjust to compiled_regex. * probe.c: Include "common/gdb_optional.h". (collect_probes): Use compiled_regex and gdb::optional and remove cleanups. * skip.c: Include "common/gdb_optional.h". (skiplist_entry::compiled_function_regexp): Now a gdb::optional<compiled_regex>. (skiplist_entry::compiled_function_regexp_is_valid): Delete field. (free_skiplist_entry): Remove regfree call. (compile_skip_regexp, skip_rfunction_p): Adjust to use compiled_regex and gdb::optional. * symtab.c: Include "common/gdb_optional.h". (search_symbols): Use compiled_regex and gdb::optional. * utils.c (do_regfree_cleanup, make_regfree_cleanup) (get_regcomp_error, compile_rx_or_error): Delete. Some bits moved to gdb_regex.c.