DB(3perl)
π DB β the Perl debug API, but make it a whole vibe π
okay bestie, listen. this is DB, from the Perl Programmers Reference Guide section 3 of the manual. it's the programmatic interface to the Perl debugging API. yes, THE debugging API. the one that actually knows what your code is doing. sit down, hydrate, we're going in π«Ά
β¨ NAME β¨
DB β programmatic interface to the Perl debugging API. that's it. that's the whole thing. iconic behavior honestly π
πΈ SYNOPSIS πΈ
here's the whole shape of it, bestie. look at her:
package CLIENT;
use DB;
@ISA = qw(DB);
# these (inherited) methods can be called by the client
CLIENT->register() # register a client package name
CLIENT->done() # de-register from the debugging API
CLIENT->skippkg('hide::hide') # ask DB not to stop in this package
CLIENT->cont([WHERE]) # run some more (until BREAK or
# another breakpoint)
CLIENT->step() # single step
CLIENT->next() # step over
CLIENT->ret() # return from current subroutine
CLIENT->backtrace() # return the call stack description
CLIENT->ready() # call when client setup is done
CLIENT->trace_toggle() # toggle subroutine call trace mode
CLIENT->subs([SUBS]) # return subroutine information
CLIENT->files() # return list of all files known to DB
CLIENT->lines() # return lines in currently loaded file
CLIENT->loadfile(FILE,LINE) # load a file and let other clients know
CLIENT->lineevents() # return info on lines with actions
CLIENT->set_break([WHERE],[COND])
CLIENT->set_tbreak([WHERE])
CLIENT->clr_breaks([LIST])
CLIENT->set_action(WHERE,ACTION)
CLIENT->clr_actions([LIST])
CLIENT->evalcode(STRING) # eval STRING in executing code's context
CLIENT->prestop([STRING]) # execute in code context before stopping
CLIENT->poststop([STRING])# execute in code context before resuming
# These methods will be called at the appropriate times.
# Stub versions provided do nothing.
# None of these can block.
CLIENT->init() # called when debug API inits itself
CLIENT->stop(FILE,LINE) # when execution stops
CLIENT->idle() # while stopped (can be a client event loop)
CLIENT->cleanup() # just before exit
CLIENT->output(LIST) # called to print any output that
# the API must show
slay. okay so basically: you inherit, you register, and the API calls you back when stuff happens. it's giving main character energy for your debugger π₯
π DESCRIPTION π
okay so here's the tea. Perl debug info is needed constantly β and not only by actual debuggers! modules that just need a lil "special" something to do their job right (looking at you, profilers π) want in too.
this module abstracts and provides all of the hooks into Perl's internal debugging functionality. so every different implementation of a Perl debugger β or any package that just wants to get at the "privileged" debugging data β can all benefit from the development of this common code. sharing is caring, periodt. currently used by Swat, the perl/Tk GUI debugger. π
also!! multiple "front-ends" can latch into this debugging API simultaneously. the whole point is stuff like debugging with a command line and a GUI at the same time, debugging debuggers, etc. genuinely unhinged in the best way π
[Sounds nice, but this needs some serious support -- GSAR]
that's a direct quote from the authors, bestie, i'm just the messenger π
now, in particular, this API does not provide the following functions:
- data display
- command processing
- command alias management
- user interface (tty or graphical)
those are intended to be services performed by the clients of this API. so like. you do your part, the API does hers. equal partnership β¨
and one more thing β this module attempts to be squeaky clean w.r.t use strict; and when warnings are enabled. no cap, she washes behind her ears π§Ό
π¦ Global Variables π¦
these "public" global names can be read by clients of this API. beware though β these should be considered "readonly". read only!! don't touch, just look, like a museum πΌοΈ
$DB::subβ name of current executing subroutine.%DB::subβ the keys of this hash are the names of all the known subroutines. each value is an encoded string that has thesprintf(3)format"("%s:%d-%d", filename, fromline, toline)".$DB::singleβ single-step flag. will be true if the API will stop at the next statement.$DB::signalβ signal flag. will be set to a true value if a signal was caught. clients may check for this flag to abort time-consuming operations.$DB::traceβ this flag is set to true if the API is tracing through subroutine calls.@DB::argsβ contains the arguments of current subroutine, or the@ARGVarray if in the toplevel context.@DB::dblineβ list of lines in currently loaded file.%DB::dblineβ actions in current file (keys are line numbers). the values are strings that have thesprintf(3)format"("%s\000%s", breakcondition, actioncode)".$DB::packageβ package namespace of currently executing code.$DB::filenameβ currently loaded filename.$DB::subnameβ fully qualified name of currently executing subroutine.$DB::linenoβ line number that will be executed next.
π API Methods π
these are the methods in the DB base class. and here's the important part bestie β a client must access these methods by inheritance (not by calling them directly!), because the API keeps track of clients through the inheritance mechanism. that's the whole trick. that's how she knows who's who π
CLIENT->register()β register a client object/packageCLIENT->evalcode(STRING)β evalSTRINGin executing code contextCLIENT->skippkg('D::hide')β ask DB not to stop in these packagesCLIENT->run()β run some more (until a breakpt is reached)CLIENT->step()β single stepCLIENT->next()β step overCLIENT->done()β de-register from the debugging API
π Client Callback Methods π
these "virtual" methods can be defined by the client. the API will call them at appropriate points. note that unless specified otherwise, the debug API only defines empty, non-functional default versions of these methods β so if you don't write them, nothing happens. ghost town. tumbleweed. π
CLIENT->init()β called after debug API inits itself.CLIENT->prestop([STRING])β usually inherited fromDBpackage. if no arguments are passed, returns the prestop action string.CLIENT->stop()β called when execution stops (w/ args file, line).CLIENT->idle()β called while stopped (can be a client event loop).CLIENT->poststop([STRING])β usually inherited fromDBpackage. if no arguments are passed, returns the poststop action string.CLIENT->evalcode(STRING)β usually inherited fromDBpackage. ask for aSTRINGto be "eval"-ed in executing code context.CLIENT->cleanup()β called just before exit.CLIENT->output(LIST)β called when API must show a message (warnings, errors etc.).
π BUGS π
the interface defined by this module is missing some of the later additions to perl's debugging functionality. as such, this interface should be considered highly experimental and subject to change.
translation: she's cute, she's useful, she is not stable. do not build your whole personality on this API. π«£
π«Ά AUTHOR π«Ά
Gurusamy Sarathy gsar@activestate.com
this code heavily adapted from an early version of perl5db.pl attributable to Larry Wall and the Perl Porters.
legend behavior. respectfully. πββοΈ
and that's the whole page, bestie!! this was perl v5.44.0, dated 2026-10-17. go forth, inherit responsibly, and remember: readonly means readonly. mwah ππ
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms