Skip to content

Commit

Permalink
gh-88226: Emit TARGET labels in Python/ceval.c when debugging, even i…
Browse files Browse the repository at this point in the history
…f computed gotos aren't enabled (GH-98265)

Keep target labels when debugging, but don't warn about lack of use.

Co-authored-by: Eryk Sun <eryksun@gmail.com>
  • Loading branch information
smontanaro and eryksun authored Nov 22, 2022
1 parent 22d91c1 commit d4cf192
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Always define ``TARGET_*`` labels in ``Python/ceval.c``, even if
``USE_COMPUTED_GOTOS`` is disabled. This allows breakpoints to be
set at those labels in (for instance) ``gdb``.
25 changes: 21 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,11 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
#endif

#if USE_COMPUTED_GOTOS
#define TARGET(op) TARGET_##op: INSTRUCTION_START(op);
#define DISPATCH_GOTO() goto *opcode_targets[opcode]
# define TARGET(op) TARGET_##op: INSTRUCTION_START(op);
# define DISPATCH_GOTO() goto *opcode_targets[opcode]
#else
#define TARGET(op) case op: INSTRUCTION_START(op);
#define DISPATCH_GOTO() goto dispatch_opcode
# define TARGET(op) case op: TARGET_##op: INSTRUCTION_START(op);
# define DISPATCH_GOTO() goto dispatch_opcode
#endif

/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
Expand Down Expand Up @@ -1056,6 +1056,18 @@ static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) {
#define KWNAMES_LEN() \
(kwnames == NULL ? 0 : ((int)PyTuple_GET_SIZE(kwnames)))

/* Disable unused label warnings. They are handy for debugging, even
if computed gotos aren't used. */

/* TBD - what about other compilers? */
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-label"
#elif defined(_MSC_VER) /* MS_WINDOWS */
# pragma warning(push)
# pragma warning(disable:4102)
#endif

PyObject* _Py_HOT_FUNCTION
_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
{
Expand Down Expand Up @@ -1435,6 +1447,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
goto error;

}
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER) /* MS_WINDOWS */
# pragma warning(pop)
#endif

static void
format_missing(PyThreadState *tstate, const char *kind,
Expand Down

0 comments on commit d4cf192

Please sign in to comment.