From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/3] Refactor body of bppy_init
Date: Thu, 8 Dec 2022 12:18:02 -0700 [thread overview]
Message-ID: <20221208191804.3819129-2-tromey@adacore.com> (raw)
In-Reply-To: <20221208191804.3819129-1-tromey@adacore.com>
This patch pulls the body of bppy_init out into a separate function.
This will simplify a subsequent patch.
---
gdb/python/py-breakpoint.c | 161 ++++++++++++++++++++-----------------
1 file changed, 87 insertions(+), 74 deletions(-)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 63b18bd0f92..917fd367d06 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -813,6 +813,90 @@ bppy_init_validate_args (const char *spec, char *source,
return 1;
}
+/* Helper function for breakpoint creation. */
+
+static void
+bppy_create_breakpoint (enum bptype type, int access_type, int temporary_bp,
+ int internal_bp, const char *spec,
+ PyObject *qualified, const char *source,
+ const char *function, const char *label,
+ const char *line)
+{
+ switch (type)
+ {
+ case bp_breakpoint:
+ case bp_hardware_breakpoint:
+ {
+ location_spec_up locspec;
+ symbol_name_match_type func_name_match_type
+ = (qualified != NULL && PyObject_IsTrue (qualified)
+ ? symbol_name_match_type::FULL
+ : symbol_name_match_type::WILD);
+
+ if (spec != NULL)
+ {
+ gdb::unique_xmalloc_ptr<char>
+ copy_holder (xstrdup (skip_spaces (spec)));
+ const char *copy = copy_holder.get ();
+
+ locspec = string_to_location_spec (©,
+ current_language,
+ func_name_match_type);
+ }
+ else
+ {
+ std::unique_ptr<explicit_location_spec> explicit_loc
+ (new explicit_location_spec ());
+
+ explicit_loc->source_filename
+ = source != nullptr ? xstrdup (source) : nullptr;
+ explicit_loc->function_name
+ = function != nullptr ? xstrdup (function) : nullptr;
+ explicit_loc->label_name
+ = label != nullptr ? xstrdup (label) : nullptr;
+
+ if (line != NULL)
+ explicit_loc->line_offset = linespec_parse_line_offset (line);
+
+ explicit_loc->func_name_match_type = func_name_match_type;
+
+ locspec.reset (explicit_loc.release ());
+ }
+
+ const struct breakpoint_ops *ops
+ = breakpoint_ops_for_location_spec (locspec.get (), false);
+
+ create_breakpoint (gdbpy_enter::get_gdbarch (),
+ locspec.get (), NULL, -1, NULL, false,
+ 0,
+ temporary_bp, type,
+ 0,
+ AUTO_BOOLEAN_TRUE,
+ ops,
+ 0, 1, internal_bp, 0);
+ break;
+ }
+ case bp_watchpoint:
+ {
+ spec = skip_spaces (spec);
+
+ if (access_type == hw_write)
+ watch_command_wrapper (spec, 0, internal_bp);
+ else if (access_type == hw_access)
+ awatch_command_wrapper (spec, 0, internal_bp);
+ else if (access_type == hw_read)
+ rwatch_command_wrapper (spec, 0, internal_bp);
+ else
+ error(_("Cannot understand watchpoint access type."));
+ break;
+ }
+ case bp_catchpoint:
+ error (_("BP_CATCHPOINT not supported"));
+ default:
+ error(_("Do not understand breakpoint type to set."));
+ }
+}
+
/* Python function to create a new breakpoint. */
static int
bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
@@ -881,80 +965,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
try
{
- switch (type)
- {
- case bp_breakpoint:
- case bp_hardware_breakpoint:
- {
- location_spec_up locspec;
- symbol_name_match_type func_name_match_type
- = (qualified != NULL && PyObject_IsTrue (qualified)
- ? symbol_name_match_type::FULL
- : symbol_name_match_type::WILD);
-
- if (spec != NULL)
- {
- gdb::unique_xmalloc_ptr<char>
- copy_holder (xstrdup (skip_spaces (spec)));
- const char *copy = copy_holder.get ();
-
- locspec = string_to_location_spec (©,
- current_language,
- func_name_match_type);
- }
- else
- {
- std::unique_ptr<explicit_location_spec> explicit_loc
- (new explicit_location_spec ());
-
- explicit_loc->source_filename
- = source != nullptr ? xstrdup (source) : nullptr;
- explicit_loc->function_name
- = function != nullptr ? xstrdup (function) : nullptr;
- explicit_loc->label_name
- = label != nullptr ? xstrdup (label) : nullptr;
-
- if (line != NULL)
- explicit_loc->line_offset
- = linespec_parse_line_offset (line.get ());
-
- explicit_loc->func_name_match_type = func_name_match_type;
-
- locspec.reset (explicit_loc.release ());
- }
-
- const struct breakpoint_ops *ops
- = breakpoint_ops_for_location_spec (locspec.get (), false);
-
- create_breakpoint (gdbpy_enter::get_gdbarch (),
- locspec.get (), NULL, -1, NULL, false,
- 0,
- temporary_bp, type,
- 0,
- AUTO_BOOLEAN_TRUE,
- ops,
- 0, 1, internal_bp, 0);
- break;
- }
- case bp_watchpoint:
- {
- spec = skip_spaces (spec);
-
- if (access_type == hw_write)
- watch_command_wrapper (spec, 0, internal_bp);
- else if (access_type == hw_access)
- awatch_command_wrapper (spec, 0, internal_bp);
- else if (access_type == hw_read)
- rwatch_command_wrapper (spec, 0, internal_bp);
- else
- error(_("Cannot understand watchpoint access type."));
- break;
- }
- case bp_catchpoint:
- error (_("BP_CATCHPOINT not supported"));
- default:
- error(_("Do not understand breakpoint type to set."));
- }
+ bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp,
+ spec, qualified, source, function, label,
+ line.get ());
}
catch (const gdb_exception &except)
{
--
2.34.3
next prev parent reply other threads:[~2022-12-08 19:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 19:18 [PATCH 0/3] Add "announce" flag to Python breakpoint creation Tom Tromey
2022-12-08 19:18 ` Tom Tromey [this message]
2022-12-08 19:18 ` [PATCH 2/3] Fix latent bug in " Tom Tromey
2023-01-12 17:44 ` Simon Marchi
2022-12-08 19:18 ` [PATCH 3/3] Let Python breakpoints be created silently Tom Tromey
2023-01-11 17:31 ` Tom Tromey
2023-01-12 9:42 ` Eli Zaretskii
2023-01-12 17:49 ` Simon Marchi
2023-01-13 18:55 ` Tom Tromey
2023-01-13 12:59 ` Pedro Alves
2023-01-13 18:56 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221208191804.3819129-2-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).