CINXE.COM

debug package - runtime/debug - Go Packages

<!DOCTYPE html> <html lang="en" data-layout="responsive" data-local=""> <head> <script> window.addEventListener('error', window.__err=function f(e){f.p=f.p||[];f.p.push(e)}); </script> <script> (function() { const theme = document.cookie.match(/prefers-color-scheme=(light|dark|auto)/)?.[1] if (theme) { document.querySelector('html').setAttribute('data-theme', theme); } }()) </script> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="Description" content="Package debug contains facilities for programs to debug themselves while they are running."> <meta class="js-gtmID" data-gtmid="GTM-W8MVQXG"> <link rel="shortcut icon" href="/static/shared/icon/favicon.ico"> <link rel="canonical" href="https://pkg.go.dev/runtime/debug"> <link href="/static/frontend/frontend.min.css?version=prod-frontend-00090-vzc" rel="stylesheet"> <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Go Packages"> <title>debug package - runtime/debug - Go Packages</title> <link href="/static/frontend/unit/unit.min.css?version=prod-frontend-00090-vzc" rel="stylesheet"> <link href="/static/frontend/unit/main/main.min.css?version=prod-frontend-00090-vzc" rel="stylesheet"> </head> <body> <script> function loadScript(src, mod = true) { let s = document.createElement('script'); s.src = src; if (mod) { s.type = 'module'; s.async = true; s.defer = true } document.head.appendChild(s); } loadScript("/third_party/dialog-polyfill/dialog-polyfill.js", false) loadScript("/static/frontend/frontend.js"); </script> <header class="go-Header go-Header--full js-siteHeader"> <div class="go-Header-inner go-Header-inner--dark"> <nav class="go-Header-nav"> <a href="https://go.dev/" class="js-headerLogo" data-gtmc="nav link" data-test-id="go-header-logo-link" role="heading" aria-level="1"> <img class="go-Header-logo" src="/static/shared/logo/go-white.svg" alt="Go"> </a> <div class="skip-navigation-wrapper"> <a class="skip-to-content-link" aria-label="Skip to main content" href="#main-content"> Skip to Main Content </a> </div> <div class="go-Header-rightContent"> <div class="go-SearchForm js-searchForm"> <form class="go-InputGroup go-ShortcutKey go-SearchForm-form" action="/search" data-shortcut="/" data-shortcut-alt="search" data-gtmc="search form" aria-label="Search for a package" role="search" > <input name="q" class="go-Input js-searchFocus" aria-label="Search for a package" type="search" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="Search packages or symbols" value="" /> <input name="m" value="" hidden> <button class="go-Button go-Button--inverted" aria-label="Submit search"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt="" /> </button> </form> <button class="go-SearchForm-expandSearch js-expandSearch" data-gtmc="nav button" aria-label="Open search" data-test-id="expand-search"> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt=""> </button> </div> <ul class="go-Header-menu"> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Why Go <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--why js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/solutions#case-studies"> </span>Case Studies</span> </a> </div> <p>Common problems companies solve with Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/solutions#use-cases"> </span>Use Cases</span> </a> </div> <p>Stories about how and why companies use Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/security/policy/"> </span>Security Policy</span> </a> </div> <p>How Go can help keep you secure by default</p> </li> </ul> </li> <li class="go-Header-menuItem"> <a href="https://go.dev/learn/" data-gtmc="nav link">Learn</a> </li> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Docs <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--docs js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/effective_go"> <span>Effective Go</span> </a> </div> <p>Tips for writing clear, performant, and idiomatic Go code</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/"> <span>Go User Manual</span> </a> </div> <p>A complete introduction to building software with Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://pkg.go.dev/std"> <span>Standard library</span> </a> </div> <p>Reference documentation for Go's standard library</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/devel/release"> <span>Release Notes</span> </a> </div> <p>Learn what's new in each Go release</p> </li> </ul> </li> <li class="go-Header-menuItem go-Header-menuItem--active"> <a href="/" data-gtmc="nav link">Packages</a> </li> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Community <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--community js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/talks/"> <span>Recorded Talks</span> </a> </div> <p>Videos from prior events</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://www.meetup.com/pro/go"> <span>Meetups</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </div> <p>Meet other local Go developers</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://github.com/golang/go/wiki/Conferences"> <span>Conferences</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </div> <p>Learn and network with Go developers from around the world</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/blog"> <span>Go blog</span> </a> </div> <p>The Go project's official blog.</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/help"> <span>Go project</span> </a> </div> <p>Get help and stay informed from Go</p> </li> <li class="go-Header-submenuItem"> <div> Get connected </div> <p></p> <div class="go-Header-socialIcons"> <a class="go-Header-socialIcon" aria-label="Get connected with google-groups (Opens in new window)" href="https://groups.google.com/g/golang-nuts" ><img src="/static/shared/logo/social/google-groups.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with github (Opens in new window)" href="https://github.com/golang"><img src="/static/shared/logo/social/github.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with twitter (Opens in new window)" href="https://twitter.com/golang"><img src="/static/shared/logo/social/twitter.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with reddit (Opens in new window)" href="https://www.reddit.com/r/golang/"><img src="/static/shared/logo/social/reddit.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with slack (Opens in new window)" href="https://invite.slack.golangbridge.org/"><img src="/static/shared/logo/social/slack.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with stack-overflow (Opens in new window)" href="https://stackoverflow.com/collectives/go"><img src="/static/shared/logo/social/stack-overflow.svg" /></a> </div> </li> </ul> </li> </ul> <button class="go-Header-navOpen js-headerMenuButton go-Header-navOpen--white" data-gtmc="nav button" aria-label="Open navigation"> </button> </div> </nav> </div> </header> <aside class="go-NavigationDrawer js-header"> <nav class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="https://go.dev/"> <img class="go-NavigationDrawer-logo" src="/static/shared/logo/go-blue.svg" alt="Go."> </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Why Go</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Why Go </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/solutions#case-studies"> Case Studies </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/solutions#use-cases"> Use Cases </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/security/policy/"> Security Policy </a> </li> </ul> </div> </div> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/learn/">Learn</a> </li> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Docs</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"><i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Docs </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/effective_go"> Effective Go </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/"> Go User Manual </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://pkg.go.dev/std"> Standard library </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/devel/release"> Release Notes </a> </li> </ul> </div> </div> </li> <li class="go-NavigationDrawer-listItem go-NavigationDrawer-listItem--active"> <a href="/">Packages</a> </li> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Community</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Community </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/talks/"> Recorded Talks </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://www.meetup.com/pro/go"> Meetups <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://github.com/golang/go/wiki/Conferences"> Conferences <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/blog"> Go blog </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/help"> Go project </a> </li> <li class="go-NavigationDrawer-listItem"> <div>Get connected</div> <div class="go-Header-socialIcons"> <a class="go-Header-socialIcon" href="https://groups.google.com/g/golang-nuts"><img src="/static/shared/logo/social/google-groups.svg" /></a> <a class="go-Header-socialIcon" href="https://github.com/golang"><img src="/static/shared/logo/social/github.svg" /></a> <a class="go-Header-socialIcon" href="https://twitter.com/golang"><img src="/static/shared/logo/social/twitter.svg" /></a> <a class="go-Header-socialIcon" href="https://www.reddit.com/r/golang/"><img src="/static/shared/logo/social/reddit.svg" /></a> <a class="go-Header-socialIcon" href="https://invite.slack.golangbridge.org/"><img src="/static/shared/logo/social/slack.svg" /></a> <a class="go-Header-socialIcon" href="https://stackoverflow.com/collectives/go"><img src="/static/shared/logo/social/stack-overflow.svg" /></a> </div> </li> </ul> </div> </div> </li> </ul> </nav> </aside> <div class="go-NavigationDrawer-scrim js-scrim" role="presentation"></div> <main class="go-Main" id="main-content"> <div class="go-Main-banner" role="alert"></div> <header class="go-Main-header js-mainHeader"> <nav class="go-Main-headerBreadcrumb go-Breadcrumb" aria-label="Breadcrumb" data-test-id="UnitHeader-breadcrumb"> <ol> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/" data-gtmc="breadcrumb link">Discover Packages</a> </li> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/std" data-gtmc="breadcrumb link">Standard library</a> </li> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/runtime@go1.23.3" data-gtmc="breadcrumb link">runtime</a> </li> <li> <a href="/runtime/debug@go1.23.3" data-gtmc="breadcrumb link" aria-current="location" data-test-id="UnitHeader-breadcrumbCurrent"> debug </a> <button class="go-Button go-Button--inline go-Clipboard js-clipboard" title="Copy path to clipboard.&#10;&#10;runtime/debug" aria-label="Copy Path to Clipboard" data-to-copy="runtime/debug" data-gtmc="breadcrumbs button" > <img class="go-Icon go-Icon--accented" height="24" width="24" src="/static/shared/icon/content_copy_gm_grey_24dp.svg" alt="" > </button> </li> </ol> </nav> <div class="go-Main-headerContent"> <div class="go-Main-headerTitle js-stickyHeader"> <a class="go-Main-headerLogo" href="https://go.dev/" aria-hidden="true" tabindex="-1" data-gtmc="header link" aria-label="Link to Go Homepage"> <img height="78" width="207" src="/static/shared/logo/go-blue.svg" alt="Go"> </a> <h1 class="UnitHeader-titleHeading" data-test-id="UnitHeader-title">debug</h1> <span class="go-Chip go-Chip--inverted">package</span> <span class="go-Chip go-Chip--inverted">standard library</span> <button class="go-Button go-Button--inline go-Clipboard js-clipboard" title="Copy path to clipboard.&#10;&#10;runtime/debug" aria-label="Copy Path to Clipboard" data-to-copy="runtime/debug" data-gtmc="title button" tabindex="-1" > <img class="go-Icon go-Icon--accented" height="24" width="24" src="/static/shared/icon/content_copy_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="go-Main-headerDetails"> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-version"> <a href="?tab=versions" aria-label="Version: go1.23.3" data-gtmc="header link" aria-describedby="version-description"> <span class="go-textSubtle" aria-hidden="true">Version: </span> go1.23.3 </a> <div class="screen-reader-only" id="version-description" hidden> Opens a new window with list of versions in this module. </div> <span class="DetailsHeader-badge--latest" data-test-id="UnitHeader-minorVersionBanner"> <span class="go-Chip DetailsHeader-span--latest">Latest</span> <span class="go-Chip DetailsHeader-span--notAtLatest"> Latest <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/alert_gm_grey_24dp.svg" alt="Warning"> </summary> <p>This package is not in the latest version of its module.</p> </details> </span> <a href="/runtime/debug" aria-label="Go to Latest Version" data-gtmc="header link"> <span class="go-Chip go-Chip--alert DetailsHeader-span--goToLatest">Go to latest</span> </a> </span> </span> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-commitTime"> Published: Nov 6, 2024 </span> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-licenses"> License: <a href="/runtime/debug@go1.23.3?tab=licenses" data-test-id="UnitHeader-license" data-gtmc="header link" aria-describedby="license-description">BSD-3-Clause</a> </span> <div class="screen-reader-only" id="license-description" hidden> Opens a new window with license information. </div> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-imports"> <a href="/runtime/debug@go1.23.3?tab=imports" aria-label="Imports: 9" data-gtmc="header link" aria-describedby="imports-description"> <span class="go-textSubtle">Imports: </span>9 </a> </span> <div class="screen-reader-only" id="imports-description" hidden> Opens a new window with list of imports. </div> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-importedby"> <a href="/runtime/debug@go1.23.3?tab=importedby" aria-label="Imported By: 45,882" data-gtmc="header link" aria-describedby="importedby-description"> <span class="go-textSubtle">Imported by: </span>45,882 </a> </span> <div class="screen-reader-only" id="importedby-description" hidden> Opens a new window with list of known importers. </div> </div> <div class="UnitHeader-overflowContainer"> <svg class="UnitHeader-overflowImage" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> <path d="M0 0h24v24H0z" fill="none"/> <path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/> </svg> <select class="UnitHeader-overflowSelect js-selectNav" tabindex="-1"> <option value="/">Main</option> <option value="/runtime/debug@go1.23.3?tab=versions"> Versions </option> <option value="/runtime/debug@go1.23.3?tab=licenses"> Licenses </option> <option value="/runtime/debug@go1.23.3?tab=imports"> Imports </option> <option value="/runtime/debug@go1.23.3?tab=importedby"> Imported By </option> </select> </div> </div> </header> <aside class="go-Main-aside js-mainAside"> <div class="UnitMeta"> <h2 class="go-textLabel">Details</h2> <ul class="UnitMeta-details"> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Valid <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/go.mod" target="_blank" rel="noopener">go.mod</a> file <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p> The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go. </p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Redistributable license <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p> Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed. </p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Tagged version <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p>Modules with tagged versions give importers more predictable builds.</p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Stable version <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p>When a project reaches major version v1 it is considered stable.</p> </details> </li> <li class="UnitMeta-detailsLearn"> <a href="/about#best-practices" data-gtmc="meta link">Learn more about best practices</a> </li> </ul> <h2 class="go-textLabel">Repository</h2> <div class="UnitMeta-repo"> <a href="https://cs.opensource.google/go/go" title="https://cs.opensource.google/go/go" target="_blank" rel="noopener"> cs.opensource.google/go/go </a> </div> <h2 class="go-textLabel">Links</h2> <ul class="UnitMeta-links"> <li> <a href="https://go.dev/security/policy" title="Report security issues in the Go standard library and sub-repositories"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/security_grey_24dp.svg" alt=""> Report a Vulnerability </a> </li> </ul> </div> </aside> <nav class="go-Main-nav go-Main-nav--sticky js-mainNav" aria-label="Outline"> <div class="go-Main-navDesktop"> <div class="UnitOutline-jumpTo"> <button class="UnitOutline-jumpToInput go-ShortcutKey js-jumpToInput" aria-controls="jump-to-modal" aria-label="Open Jump to Identifier" data-shortcut="f" data-shortcut-alt="find" data-test-id="jump-to-button" data-gtmc="outline button"> Jump to ... </button> </div> <ul class="go-Tree js-tree" role="tree" aria-label="Outline"> <li> <a href="#section-documentation" data-gtmc="outline link"> Documentation </a> <ul> <li> <a href="#pkg-overview" data-gtmc="doc outline link">Overview</a> </li> <li class="DocNav-overview"> <a href="#pkg-index" data-gtmc="doc outline link"> Index </a> <ul> <li> <a href="#pkg-examples" data-gtmc="doc outline link"> Examples </a> </li> </ul> </li> <li class="DocNav-constants"> <a href="#pkg-constants" data-gtmc="doc outline link"> Constants </a> </li> <li class="DocNav-variables"> <a href="#pkg-variables" data-gtmc="doc outline link"> Variables </a> </li> <li class="DocNav-functions"> <a href="#pkg-functions" data-gtmc="doc outline link"> Functions </a> <ul> <li> <a href="#FreeOSMemory" title="FreeOSMemory()" data-gtmc="doc outline link"> FreeOSMemory() </a> </li> <li> <a href="#PrintStack" title="PrintStack()" data-gtmc="doc outline link"> PrintStack() </a> </li> <li> <a href="#ReadGCStats" title="ReadGCStats(stats)" data-gtmc="doc outline link"> ReadGCStats(stats) </a> </li> <li> <a href="#SetCrashOutput" title="SetCrashOutput(f, opts)" data-gtmc="doc outline link"> SetCrashOutput(f, opts) </a> </li> <li> <a href="#SetGCPercent" title="SetGCPercent(percent)" data-gtmc="doc outline link"> SetGCPercent(percent) </a> </li> <li> <a href="#SetMaxStack" title="SetMaxStack(bytes)" data-gtmc="doc outline link"> SetMaxStack(bytes) </a> </li> <li> <a href="#SetMaxThreads" title="SetMaxThreads(threads)" data-gtmc="doc outline link"> SetMaxThreads(threads) </a> </li> <li> <a href="#SetMemoryLimit" title="SetMemoryLimit(limit)" data-gtmc="doc outline link"> SetMemoryLimit(limit) </a> </li> <li> <a href="#SetPanicOnFault" title="SetPanicOnFault(enabled)" data-gtmc="doc outline link"> SetPanicOnFault(enabled) </a> </li> <li> <a href="#SetTraceback" title="SetTraceback(level)" data-gtmc="doc outline link"> SetTraceback(level) </a> </li> <li> <a href="#Stack" title="Stack()" data-gtmc="doc outline link"> Stack() </a> </li> <li> <a href="#WriteHeapDump" title="WriteHeapDump(fd)" data-gtmc="doc outline link"> WriteHeapDump(fd) </a> </li> </ul> </li> <li class="DocNav-types"> <a href="#pkg-types" data-gtmc="doc outline link"> Types </a> <ul> <li> <a href="#BuildInfo" title="type BuildInfo" data-gtmc="doc outline link"> type BuildInfo </a> <ul> <li> <a href="#ParseBuildInfo" title="ParseBuildInfo(data)" data-gtmc="doc outline link"> ParseBuildInfo(data) </a> </li> <li> <a href="#ReadBuildInfo" title="ReadBuildInfo()" data-gtmc="doc outline link"> ReadBuildInfo() </a> </li> <li> <a href="#BuildInfo.String" title="(bi) String()" data-gtmc="doc outline link"> (bi) String() </a> </li> </ul> </li> <li> <a href="#BuildSetting" title="type BuildSetting" data-gtmc="doc outline link"> type BuildSetting </a> </li> <li> <a href="#CrashOptions" title="type CrashOptions" data-gtmc="doc outline link"> type CrashOptions </a> </li> <li> <a href="#GCStats" title="type GCStats" data-gtmc="doc outline link"> type GCStats </a> </li> <li> <a href="#Module" title="type Module" data-gtmc="doc outline link"> type Module </a> </li> </ul> </li> </ul> </li> <li> <a href="#section-sourcefiles" data-gtmc="outline link"> Source Files </a> </li> </ul> </div> <div class="go-Main-navMobile js-mainNavMobile"> <label class="go-Label"> <select class="go-Select"> <option selected disabled>Documentation</option> </select> </label> </div> </nav> <article class="go-Main-article js-mainContent"> <div class="UnitDetails" data-test-id="UnitDetails" style="display: block;"> <div class="UnitDetails-content js-unitDetailsContent" data-test-id="UnitDetails-content"> <div class="UnitDoc"> <h2 class="UnitDoc-title" id="section-documentation"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/code_gm_grey_24dp.svg" alt=""> Documentation <a class="UnitDoc-idLink" href="#section-documentation" aria-label="Go to Documentation">露</a> </h2> <div class="UnitBuildContext-titleContext"> <label> <a href="https://go.dev/about#build-context" class="UnitBuildContext-link">Rendered for</a> <select class="go-Select js-buildContextSelect"> <option value="linux">linux/amd64</option> <option value="windows">windows/amd64</option> <option value="darwin">darwin/amd64</option> <option value="js">js/wasm</option> </select> </label> </div> <div class="Documentation js-documentation"> <div class="Documentation-content js-docContent"> <section class="Documentation-overview"> <h3 tabindex="-1" id="pkg-overview" class="Documentation-overviewHeader">Overview <a href="#pkg-overview" aria-label="Go to Overview">露</a></h3> <p>Package debug contains facilities for programs to debug themselves while they are running. </p> </section><section class="Documentation-index"> <h3 id="pkg-index" class="Documentation-indexHeader">Index <a href="#pkg-index" aria-label="Go to Index">露</a></h3> <ul class="Documentation-indexList"> <li class="Documentation-indexFunction"> <a href="#FreeOSMemory">func FreeOSMemory()</a></li> <li class="Documentation-indexFunction"> <a href="#PrintStack">func PrintStack()</a></li> <li class="Documentation-indexFunction"> <a href="#ReadGCStats">func ReadGCStats(stats *GCStats)</a></li> <li class="Documentation-indexFunction"> <a href="#SetCrashOutput">func SetCrashOutput(f *os.File, opts CrashOptions) error</a></li> <li class="Documentation-indexFunction"> <a href="#SetGCPercent">func SetGCPercent(percent int) int</a></li> <li class="Documentation-indexFunction"> <a href="#SetMaxStack">func SetMaxStack(bytes int) int</a></li> <li class="Documentation-indexFunction"> <a href="#SetMaxThreads">func SetMaxThreads(threads int) int</a></li> <li class="Documentation-indexFunction"> <a href="#SetMemoryLimit">func SetMemoryLimit(limit int64) int64</a></li> <li class="Documentation-indexFunction"> <a href="#SetPanicOnFault">func SetPanicOnFault(enabled bool) bool</a></li> <li class="Documentation-indexFunction"> <a href="#SetTraceback">func SetTraceback(level string)</a></li> <li class="Documentation-indexFunction"> <a href="#Stack">func Stack() []byte</a></li> <li class="Documentation-indexFunction"> <a href="#WriteHeapDump">func WriteHeapDump(fd uintptr)</a></li> <li class="Documentation-indexType"> <a href="#BuildInfo">type BuildInfo</a></li> <li><ul class="Documentation-indexTypeFunctions"> <li> <a href="#ParseBuildInfo">func ParseBuildInfo(data string) (bi *BuildInfo, err error)</a></li> <li> <a href="#ReadBuildInfo">func ReadBuildInfo() (info *BuildInfo, ok bool)</a></li> </ul></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#BuildInfo.String">func (bi *BuildInfo) String() string</a></li> </ul></li> <li class="Documentation-indexType"> <a href="#BuildSetting">type BuildSetting</a></li> <li class="Documentation-indexType"> <a href="#CrashOptions">type CrashOptions</a></li> <li class="Documentation-indexType"> <a href="#GCStats">type GCStats</a></li> <li class="Documentation-indexType"> <a href="#Module">type Module</a></li> </ul> </section><section class="Documentation-examples"> <h4 tabindex="-1" id="pkg-examples" class="Documentation-examplesHeader">Examples <a class="Documentation-idLink" href="#pkg-examples" aria-label="Go to Examples">露</a></h4> <ul class="Documentation-examplesList"> <li><a href="#example-SetCrashOutput-Monitor" class="js-exampleHref">SetCrashOutput (Monitor)</a></li> </ul> </section><h3 tabindex="-1" id="pkg-constants" class="Documentation-constantsHeader">Constants <a href="#pkg-constants" aria-label="Go to Constants">露</a></h3> <section class="Documentation-constants"><p class="Documentation-empty">This section is empty.</p></section> <h3 tabindex="-1" id="pkg-variables" class="Documentation-variablesHeader">Variables <a href="#pkg-variables" aria-label="Go to Variables">露</a></h3> <section class="Documentation-variables"><p class="Documentation-empty">This section is empty.</p></section> <h3 tabindex="-1" id="pkg-functions" class="Documentation-functionsHeader">Functions <a href="#pkg-functions" aria-label="Go to Functions">露</a></h3> <section class="Documentation-functions"><div class="Documentation-function"> <h4 tabindex="-1" id="FreeOSMemory" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=101">FreeOSMemory</a> <a class="Documentation-idLink" href="#FreeOSMemory" aria-label="Go to FreeOSMemory">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.1</span> </span> </h4> <div class="Documentation-declaration"> <pre>func FreeOSMemory()</pre> </div> <p>FreeOSMemory forces a garbage collection followed by an attempt to return as much memory to the operating system as possible. (Even if this is not called, the runtime gradually returns memory to the operating system in a background task.) </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="PrintStack" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/stack.go;l=17">PrintStack</a> <a class="Documentation-idLink" href="#PrintStack" aria-label="Go to PrintStack">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func PrintStack()</pre> </div> <p>PrintStack prints to standard error the stack trace returned by runtime.Stack. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="ReadGCStats" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=31">ReadGCStats</a> <a class="Documentation-idLink" href="#ReadGCStats" aria-label="Go to ReadGCStats">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.1</span> </span> </h4> <div class="Documentation-declaration"> <pre>func ReadGCStats(stats *<a href="#GCStats">GCStats</a>)</pre> </div> <p>ReadGCStats reads statistics about garbage collection into stats. The number of entries in the pause history is system-dependent; stats.Pause slice will be reused if large enough, reallocated otherwise. ReadGCStats may use the full capacity of the stats.Pause slice. If stats.PauseQuantiles is non-empty, ReadGCStats fills it with quantiles summarizing the distribution of pause time. For example, if len(stats.PauseQuantiles) is 5, it will be filled with the minimum, 25%, 50%, 75%, and maximum pause times. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetCrashOutput" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/stack.go;l=49">SetCrashOutput</a> <a class="Documentation-idLink" href="#SetCrashOutput" aria-label="Go to SetCrashOutput">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.23.0</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetCrashOutput(f *<a href="/os">os</a>.<a href="/os#File">File</a>, opts <a href="#CrashOptions">CrashOptions</a>) <a href="/builtin#error">error</a></pre> </div> <p>SetCrashOutput configures a single additional file where unhandled panics and other fatal errors are printed, in addition to standard error. There is only one additional file: calling SetCrashOutput again overrides any earlier call. SetCrashOutput duplicates f&#39;s file descriptor, so the caller may safely close f as soon as SetCrashOutput returns. To disable this additional crash output, call SetCrashOutput(nil). If called concurrently with a crash, some in-progress output may be written to the old file even after an overriding SetCrashOutput returns. </p> <details tabindex="-1" id="example-SetCrashOutput-Monitor" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example (Monitor) <a href="#example-SetCrashOutput-Monitor" aria-label="Go to Example (Monitor)">露</a></summary> <div class="Documentation-exampleDetailsBody"> <p>ExampleSetCrashOutput_monitor shows an example of using <a href="#SetCrashOutput">debug.SetCrashOutput</a> to direct crashes to a &#34;monitor&#34; process, for automated crash reporting. The monitor is the same executable, invoked in a special mode indicated by an environment variable. </p> <pre class="Documentation-exampleCode"> package main import ( &#34;io&#34; &#34;log&#34; &#34;os&#34; &#34;os/exec&#34; &#34;runtime/debug&#34; ) // ExampleSetCrashOutput_monitor shows an example of using // [debug.SetCrashOutput] to direct crashes to a &#34;monitor&#34; process, // for automated crash reporting. The monitor is the same executable, // invoked in a special mode indicated by an environment variable. func main() { appmain() // This Example doesn&#39;t actually run as a test because its // purpose is to crash, so it has no &#34;Output:&#34; comment // within the function body. // // To observe the monitor in action, replace the entire text // of this comment with &#34;Output:&#34; and run this command: // // $ go test -run=ExampleSetCrashOutput_monitor runtime/debug // panic: oops // ...stack... // monitor: saved crash report at /tmp/10804884239807998216.crash } // appmain represents the &#39;main&#39; function of your application. func appmain() { monitor() // Run the application. println(&#34;hello&#34;) panic(&#34;oops&#34;) } // monitor starts the monitor process, which performs automated // crash reporting. Call this function immediately within main. // // This function re-executes the same executable as a child process, // in a special mode. In that mode, the call to monitor will never // return. func monitor() { const monitorVar = &#34;RUNTIME_DEBUG_MONITOR&#34; if os.Getenv(monitorVar) != &#34;&#34; { // This is the monitor (child) process. log.SetFlags(0) log.SetPrefix(&#34;monitor: &#34;) crash, err := io.ReadAll(os.Stdin) if err != nil { log.Fatalf(&#34;failed to read from input pipe: %v&#34;, err) } if len(crash) == 0 { // Parent process terminated without reporting a crash. os.Exit(0) } // Save the crash report securely in the file system. f, err := os.CreateTemp(&#34;&#34;, &#34;*.crash&#34;) if err != nil { log.Fatal(err) } if _, err := f.Write(crash); err != nil { log.Fatal(err) } if err := f.Close(); err != nil { log.Fatal(err) } log.Fatalf(&#34;saved crash report at %s&#34;, f.Name()) } // This is the application process. // Fork+exec the same executable in monitor mode. exe, err := os.Executable() if err != nil { log.Fatal(err) } cmd := exec.Command(exe, &#34;-test.run=ExampleSetCrashOutput_monitor&#34;) cmd.Env = append(os.Environ(), monitorVar+&#34;=1&#34;) cmd.Stderr = os.Stderr cmd.Stdout = os.Stderr pipe, err := cmd.StdinPipe() if err != nil { log.Fatalf(&#34;StdinPipe: %v&#34;, err) } debug.SetCrashOutput(pipe.(*os.File), debug.CrashOptions{}) // (this conversion is safe) if err := cmd.Start(); err != nil { log.Fatalf(&#34;can&#39;t start monitor: %v&#34;, err) } // Now return and start the application proper... } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput"></span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetGCPercent" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=93">SetGCPercent</a> <a class="Documentation-idLink" href="#SetGCPercent" aria-label="Go to SetGCPercent">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.1</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetGCPercent(percent <a href="/builtin#int">int</a>) <a href="/builtin#int">int</a></pre> </div> <p>SetGCPercent sets the garbage collection target percentage: a collection is triggered when the ratio of freshly allocated data to live data remaining after the previous collection reaches this percentage. SetGCPercent returns the previous setting. The initial setting is the value of the GOGC environment variable at startup, or 100 if the variable is not set. This setting may be effectively reduced in order to maintain a memory limit. A negative percentage effectively disables garbage collection, unless the memory limit is reached. See SetMemoryLimit for more details. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetMaxStack" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=117">SetMaxStack</a> <a class="Documentation-idLink" href="#SetMaxStack" aria-label="Go to SetMaxStack">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.2</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetMaxStack(bytes <a href="/builtin#int">int</a>) <a href="/builtin#int">int</a></pre> </div> <p>SetMaxStack sets the maximum amount of memory that can be used by a single goroutine stack. If any goroutine exceeds this limit while growing its stack, the program crashes. SetMaxStack returns the previous setting. The initial setting is 1 GB on 64-bit systems, 250 MB on 32-bit systems. There may be a system-imposed maximum stack limit regardless of the value provided to SetMaxStack. </p><p>SetMaxStack is useful mainly for limiting the damage done by goroutines that enter an infinite recursion. It only limits future stack growth. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetMaxThreads" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=135">SetMaxThreads</a> <a class="Documentation-idLink" href="#SetMaxThreads" aria-label="Go to SetMaxThreads">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.2</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetMaxThreads(threads <a href="/builtin#int">int</a>) <a href="/builtin#int">int</a></pre> </div> <p>SetMaxThreads sets the maximum number of operating system threads that the Go program can use. If it attempts to use more than this many, the program crashes. SetMaxThreads returns the previous setting. The initial setting is 10,000 threads. </p><p>The limit controls the number of operating system threads, not the number of goroutines. A Go program creates a new thread only when a goroutine is ready to run but all the existing threads are blocked in system calls, cgo calls, or are locked to other goroutines due to use of runtime.LockOSThread. </p><p>SetMaxThreads is useful mainly for limiting the damage done by programs that create an unbounded number of threads. The idea is to take down the program before it takes down the operating system. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetMemoryLimit" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=234">SetMemoryLimit</a> <a class="Documentation-idLink" href="#SetMemoryLimit" aria-label="Go to SetMemoryLimit">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.19</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetMemoryLimit(limit <a href="/builtin#int64">int64</a>) <a href="/builtin#int64">int64</a></pre> </div> <p>SetMemoryLimit provides the runtime with a soft memory limit. </p><p>The runtime undertakes several processes to try to respect this memory limit, including adjustments to the frequency of garbage collections and returning memory to the underlying system more aggressively. This limit will be respected even if GOGC=off (or, if SetGCPercent(-1) is executed). </p><p>The input limit is provided as bytes, and includes all memory mapped, managed, and not released by the Go runtime. Notably, it does not account for space used by the Go binary and memory external to Go, such as memory managed by the underlying system on behalf of the process, or memory managed by non-Go code inside the same process. Examples of excluded memory sources include: OS kernel memory held on behalf of the process, memory allocated by C code, and memory mapped by syscall.Mmap (because it is not managed by the Go runtime). </p><p>More specifically, the following expression accurately reflects the value the runtime attempts to maintain as the limit: </p><pre>runtime.MemStats.Sys - runtime.MemStats.HeapReleased </pre><p>or in terms of the runtime/metrics package: </p><pre>/memory/classes/total:bytes - /memory/classes/heap/released:bytes </pre><p>A zero limit or a limit that&#39;s lower than the amount of memory used by the Go runtime may cause the garbage collector to run nearly continuously. However, the application may still make progress. </p><p>The memory limit is always respected by the Go runtime, so to effectively disable this behavior, set the limit very high. <a href="/math#MaxInt64">math.MaxInt64</a> is the canonical value for disabling the limit, but values much greater than the available memory on the underlying system work just as well. </p><p>See <a href="https://go.dev/doc/gc-guide">https://go.dev/doc/gc-guide</a> for a detailed guide explaining the soft memory limit in more detail, as well as a variety of common use-cases and scenarios. </p><p>The initial setting is math.MaxInt64 unless the GOMEMLIMIT environment variable is set, in which case it provides the initial setting. GOMEMLIMIT is a numeric value in bytes with an optional unit suffix. The supported suffixes include B, KiB, MiB, GiB, and TiB. These suffixes represent quantities of bytes as defined by the IEC 80000-13 standard. That is, they are based on powers of two: KiB means 2^10 bytes, MiB means 2^20 bytes, and so on. </p><p>SetMemoryLimit returns the previously set memory limit. A negative input does not adjust the limit, and allows for retrieval of the currently set memory limit. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetPanicOnFault" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=155">SetPanicOnFault</a> <a class="Documentation-idLink" href="#SetPanicOnFault" aria-label="Go to SetPanicOnFault">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.3</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetPanicOnFault(enabled <a href="/builtin#bool">bool</a>) <a href="/builtin#bool">bool</a></pre> </div> <p>SetPanicOnFault controls the runtime&#39;s behavior when a program faults at an unexpected (non-nil) address. Such faults are typically caused by bugs such as runtime memory corruption, so the default response is to crash the program. Programs working with memory-mapped files or unsafe manipulation of memory may cause faults at non-nil addresses in less dramatic situations; SetPanicOnFault allows such programs to request that the runtime trigger only a panic, not a crash. The runtime.Error that the runtime panics with may have an additional method: </p><pre>Addr() uintptr </pre><p>If that method exists, it returns the memory address which triggered the fault. The results of Addr are best-effort and the veracity of the result may depend on the platform. SetPanicOnFault applies only to the current goroutine. It returns the previous setting. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="SetTraceback" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=179">SetTraceback</a> <a class="Documentation-idLink" href="#SetTraceback" aria-label="Go to SetTraceback">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.6</span> </span> </h4> <div class="Documentation-declaration"> <pre>func SetTraceback(level <a href="/builtin#string">string</a>)</pre> </div> <p>SetTraceback sets the amount of detail printed by the runtime in the traceback it prints before exiting due to an unrecovered panic or an internal runtime error. The level argument takes the same values as the GOTRACEBACK environment variable. For example, SetTraceback(&#34;all&#34;) ensure that the program prints all goroutines when it crashes. See the package runtime documentation for details. If SetTraceback is called with a level lower than that of the environment variable, the call is ignored. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Stack" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/stack.go;l=23">Stack</a> <a class="Documentation-idLink" href="#Stack" aria-label="Go to Stack">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Stack() []<a href="/builtin#byte">byte</a></pre> </div> <p>Stack returns a formatted stack trace of the goroutine that calls it. It calls <a href="/runtime#Stack">runtime.Stack</a> with a large enough buffer to capture the entire trace. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="WriteHeapDump" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=168">WriteHeapDump</a> <a class="Documentation-idLink" href="#WriteHeapDump" aria-label="Go to WriteHeapDump">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.3</span> </span> </h4> <div class="Documentation-declaration"> <pre>func WriteHeapDump(fd <a href="/builtin#uintptr">uintptr</a>)</pre> </div> <p>WriteHeapDump writes a description of the heap and the objects in it to the given file descriptor. </p><p>WriteHeapDump suspends the execution of all goroutines until the heap dump is completely written. Thus, the file descriptor must not be connected to a pipe or socket whose other end is in the same Go process; instead, use a temporary file or network socket. </p><p>The heap dump format is defined at <a href="https://golang.org/s/go15heapdump">https://golang.org/s/go15heapdump</a>. </p> </div></section> <h3 tabindex="-1" id="pkg-types" class="Documentation-typesHeader">Types <a href="#pkg-types" aria-label="Go to Types">露</a></h3> <section class="Documentation-types"><div class="Documentation-type"> <h4 tabindex="-1" id="BuildInfo" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go;l=41">BuildInfo</a> <a class="Documentation-idLink" href="#BuildInfo" aria-label="Go to BuildInfo">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.12</span> </span> </h4> <div class="Documentation-declaration"> <pre>type BuildInfo struct { <span id="BuildInfo.GoVersion" data-kind="field"> <span class="comment">// GoVersion is the version of the Go toolchain that built the binary</span> </span> <span class="comment">// (for example, &#34;go1.19.2&#34;).</span> GoVersion <a href="/builtin#string">string</a> <span id="BuildInfo.Path" data-kind="field"> <span class="comment">// Path is the package path of the main package for the binary</span> </span> <span class="comment">// (for example, &#34;golang.org/x/tools/cmd/stringer&#34;).</span> Path <a href="/builtin#string">string</a> <span id="BuildInfo.Main" data-kind="field"> <span class="comment">// Main describes the module that contains the main package for the binary.</span> </span> Main <a href="#Module">Module</a> <span id="BuildInfo.Deps" data-kind="field"> <span class="comment">// Deps describes all the dependency modules, both direct and indirect,</span> </span> <span class="comment">// that contributed packages to the build of this binary.</span> Deps []*<a href="#Module">Module</a> <span id="BuildInfo.Settings" data-kind="field"> <span class="comment">// Settings describes the build settings used to build the binary.</span> </span> Settings []<a href="#BuildSetting">BuildSetting</a> }</pre> </div> <p>BuildInfo represents the build information read from a Go binary. </p> <div class="Documentation-typeFunc"> <h4 tabindex="-1" id="ParseBuildInfo" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go;l=149">ParseBuildInfo</a> <a class="Documentation-idLink" href="#ParseBuildInfo" aria-label="Go to ParseBuildInfo">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.18</span> </span> </h4> <div class="Documentation-declaration"> <pre>func ParseBuildInfo(data <a href="/builtin#string">string</a>) (bi *<a href="#BuildInfo">BuildInfo</a>, err <a href="/builtin#error">error</a>)</pre> </div> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="ReadBuildInfo" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go;l=20">ReadBuildInfo</a> <a class="Documentation-idLink" href="#ReadBuildInfo" aria-label="Go to ReadBuildInfo">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.12</span> </span> </h4> <div class="Documentation-declaration"> <pre>func ReadBuildInfo() (info *<a href="#BuildInfo">BuildInfo</a>, ok <a href="/builtin#bool">bool</a>)</pre> </div> <p>ReadBuildInfo returns the build information embedded in the running binary. The information is available only in binaries built with module support. </p> </div><div class="Documentation-typeMethod"> <h4 tabindex="-1" id="BuildInfo.String" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*BuildInfo) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go;l=104">String</a> <a class="Documentation-idLink" href="#BuildInfo.String" aria-label="Go to BuildInfo.String">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.18</span> </span> </h4> <div class="Documentation-declaration"> <pre>func (bi *<a href="#BuildInfo">BuildInfo</a>) String() <a href="/builtin#string">string</a></pre> </div> </div> </div><div class="Documentation-type"> <h4 tabindex="-1" id="BuildSetting" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go;l=87">BuildSetting</a> <a class="Documentation-idLink" href="#BuildSetting" aria-label="Go to BuildSetting">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.18</span> </span> </h4> <div class="Documentation-declaration"> <pre>type BuildSetting struct { <span id="BuildSetting.Key" data-kind="field"><span id="BuildSetting.Value" data-kind="field"> <span class="comment">// Key and Value describe the build setting.</span> </span> <span class="comment">// Key must not contain an equals sign, space, tab, or newline.</span> <span class="comment">// Value must not contain newlines (&#39;\n&#39;).</span> Key, Value <a href="/builtin#string">string</a> }</pre> </div> <p>A BuildSetting is a key-value pair describing one setting that influenced a build. </p><p>Defined keys include: </p><ul class="Documentation-bulletList"> <li>-buildmode: the buildmode flag used (typically &#34;exe&#34;)</li> <li>-compiler: the compiler toolchain flag used (typically &#34;gc&#34;)</li> <li>CGO_ENABLED: the effective CGO_ENABLED environment variable</li> <li>CGO_CFLAGS: the effective CGO_CFLAGS environment variable</li> <li>CGO_CPPFLAGS: the effective CGO_CPPFLAGS environment variable</li> <li>CGO_CXXFLAGS: the effective CGO_CXXFLAGS environment variable</li> <li>CGO_LDFLAGS: the effective CGO_LDFLAGS environment variable</li> <li>GOARCH: the architecture target</li> <li>GOAMD64/GOARM/GO386/etc: the architecture feature level for GOARCH</li> <li>GOOS: the operating system target</li> <li>vcs: the version control system for the source tree where the build ran</li> <li>vcs.revision: the revision identifier for the current commit or checkout</li> <li>vcs.time: the modification time associated with vcs.revision, in RFC3339 format</li> <li>vcs.modified: true or false indicating whether the source tree had local modifications</li> </ul> </div><div class="Documentation-type"> <h4 tabindex="-1" id="CrashOptions" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/stack.go;l=36">CrashOptions</a> <a class="Documentation-idLink" href="#CrashOptions" aria-label="Go to CrashOptions">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.23.0</span> </span> </h4> <div class="Documentation-declaration"> <pre>type CrashOptions struct { }</pre> </div> <p>CrashOptions provides options that control the formatting of the fatal crash message. </p> </div><div class="Documentation-type"> <h4 tabindex="-1" id="GCStats" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go;l=14">GCStats</a> <a class="Documentation-idLink" href="#GCStats" aria-label="Go to GCStats">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.1</span> </span> </h4> <div class="Documentation-declaration"> <pre>type GCStats struct { <span id="GCStats.LastGC" data-kind="field"> LastGC <a href="/time">time</a>.<a href="/time#Time">Time</a> <span class="comment">// time of last collection</span> </span><span id="GCStats.NumGC" data-kind="field"> NumGC <a href="/builtin#int64">int64</a> <span class="comment">// number of garbage collections</span> </span><span id="GCStats.PauseTotal" data-kind="field"> PauseTotal <a href="/time">time</a>.<a href="/time#Duration">Duration</a> <span class="comment">// total pause for all collections</span> </span><span id="GCStats.Pause" data-kind="field"> Pause []<a href="/time">time</a>.<a href="/time#Duration">Duration</a> <span class="comment">// pause history, most recent first</span> </span><span id="GCStats.PauseEnd" data-kind="field"> PauseEnd []<a href="/time">time</a>.<a href="/time#Time">Time</a> <span class="comment">// pause end times history, most recent first</span> </span><span id="GCStats.PauseQuantiles" data-kind="field"> PauseQuantiles []<a href="/time">time</a>.<a href="/time#Duration">Duration</a> </span>}</pre> </div> <p>GCStats collect information about recent garbage collections. </p> </div><div class="Documentation-type"> <h4 tabindex="-1" id="Module" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go;l=62">Module</a> <a class="Documentation-idLink" href="#Module" aria-label="Go to Module">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.12</span> </span> </h4> <div class="Documentation-declaration"> <pre>type Module struct { <span id="Module.Path" data-kind="field"> Path <a href="/builtin#string">string</a> <span class="comment">// module path</span> </span><span id="Module.Version" data-kind="field"> Version <a href="/builtin#string">string</a> <span class="comment">// module version</span> </span><span id="Module.Sum" data-kind="field"> Sum <a href="/builtin#string">string</a> <span class="comment">// checksum</span> </span><span id="Module.Replace" data-kind="field"> Replace *<a href="#Module">Module</a> <span class="comment">// replaced by this module</span> </span>}</pre> </div> <p>A Module describes a single module included in a build. </p> </div></section></div> </div> </div> <div class="UnitFiles js-unitFiles"> <h2 class="UnitFiles-title" id="section-sourcefiles"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/insert_drive_file_gm_grey_24dp.svg" alt=""> Source Files <a class="UnitFiles-idLink" href="#section-sourcefiles" aria-label="Go to Source Files">露</a> </h2> <div class="UnitFiles-titleLink"> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug" target="_blank" rel="noopener">View all Source files</a> </div> <div> <ul class="UnitFiles-fileList"><li> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/garbage.go" target="_blank" rel="noopener" title="garbage.go">garbage.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/mod.go" target="_blank" rel="noopener" title="mod.go">mod.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/stack.go" target="_blank" rel="noopener" title="stack.go">stack.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/runtime/debug/stubs.go" target="_blank" rel="noopener" title="stubs.go">stubs.go</a> </li></ul> </div> </div> </div> </div> <div id="showInternal-description" hidden> Click to show internal directories. </div> <div id="hideInternal-description" hidden> Click to hide internal directories. </div> </article> <footer class="go-Main-footer"></footer> </main> <footer class="go-Footer"> <div class="go-Footer-links"> <div class="go-Footer-linkColumn"> <a href="https://go.dev/solutions" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Why Go </a> <a href="https://go.dev/solutions#use-cases" class="go-Footer-link" data-gtmc="footer link"> Use Cases </a> <a href="https://go.dev/solutions#case-studies" class="go-Footer-link" data-gtmc="footer link"> Case Studies </a> </div> <div class="go-Footer-linkColumn"> <a href="https://learn.go.dev/" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Get Started </a> <a href="https://play.golang.org" class="go-Footer-link" data-gtmc="footer link"> Playground </a> <a href="https://tour.golang.org" class="go-Footer-link" data-gtmc="footer link"> Tour </a> <a href="https://stackoverflow.com/questions/tagged/go?tab=Newest" class="go-Footer-link" data-gtmc="footer link"> Stack Overflow </a> <a href="https://go.dev/help" class="go-Footer-link" data-gtmc="footer link"> Help </a> </div> <div class="go-Footer-linkColumn"> <a href="https://pkg.go.dev" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Packages </a> <a href="/std" class="go-Footer-link" data-gtmc="footer link"> Standard Library </a> <a href="/golang.org/x" class="go-Footer-link" data-gtmc="footer link"> Sub-repositories </a> <a href="https://pkg.go.dev/about" class="go-Footer-link" data-gtmc="footer link"> About Go Packages </a> </div> <div class="go-Footer-linkColumn"> <a href="https://go.dev/project" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> About </a> <a href="https://go.dev/dl/" class="go-Footer-link" data-gtmc="footer link">Download</a> <a href="https://go.dev/blog" class="go-Footer-link" data-gtmc="footer link">Blog</a> <a href="https://github.com/golang/go/issues" class="go-Footer-link" data-gtmc="footer link"> Issue Tracker </a> <a href="https://go.dev/doc/devel/release.html" class="go-Footer-link" data-gtmc="footer link"> Release Notes </a> <a href="https://blog.golang.org/go-brand" class="go-Footer-link" data-gtmc="footer link"> Brand Guidelines </a> <a href="https://go.dev/conduct" class="go-Footer-link" data-gtmc="footer link"> Code of Conduct </a> </div> <div class="go-Footer-linkColumn"> <a href="https://www.twitter.com/golang" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Connect </a> <a href="https://www.twitter.com/golang" class="go-Footer-link" data-gtmc="footer link"> Twitter </a> <a href="https://github.com/golang" class="go-Footer-link" data-gtmc="footer link">GitHub</a> <a href="https://invite.slack.golangbridge.org/" class="go-Footer-link" data-gtmc="footer link"> Slack </a> <a href="https://reddit.com/r/golang" class="go-Footer-link" data-gtmc="footer link"> r/golang </a> <a href="https://www.meetup.com/pro/go" class="go-Footer-link" data-gtmc="footer link"> Meetup </a> <a href="https://golangweekly.com/" class="go-Footer-link" data-gtmc="footer link"> Golang Weekly </a> </div> </div> <div class="go-Footer-bottom"> <img class="go-Footer-gopher" width="1431" height="901" src="/static/shared/gopher/pilot-bust-1431x901.svg" alt="Gopher in flight goggles"> <ul class="go-Footer-listRow"> <li class="go-Footer-listItem"> <a href="https://go.dev/copyright" data-gtmc="footer link">Copyright</a> </li> <li class="go-Footer-listItem"> <a href="https://go.dev/tos" data-gtmc="footer link">Terms of Service</a> </li> <li class="go-Footer-listItem"> <a href="http://www.google.com/intl/en/policies/privacy/" data-gtmc="footer link" target="_blank" rel="noopener"> Privacy Policy </a> </li> <li class="go-Footer-listItem"> <a href="https://go.dev/s/pkgsite-feedback" target="_blank" rel="noopener" data-gtmc="footer link"> Report an Issue </a> </li> <li class="go-Footer-listItem"> <button class="go-Button go-Button--text go-Footer-toggleTheme js-toggleTheme" aria-label="Theme Toggle"> <img data-value="auto" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/brightness_6_gm_grey_24dp.svg" alt="System theme"> <img data-value="dark" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/brightness_2_gm_grey_24dp.svg" alt="Dark theme"> <img data-value="light" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/light_mode_gm_grey_24dp.svg" alt="Light theme"> <p> Theme Toggle </p> </button> </li> <li class="go-Footer-listItem"> <button class="go-Button go-Button--text go-Footer-keyboard js-openShortcuts" aria-label="Shorcuts Modal"> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/keyboard_grey_24dp.svg" alt=""> <p> Shortcuts Modal </p> </button> </li> </ul> <a class="go-Footer-googleLogo" href="https://google.com" target="_blank"rel="noopener" data-gtmc="footer link"> <img class="go-Footer-googleLogoImg" height="24" width="72" src="/static/shared/logo/google-white.svg" alt="Google logo"> </a> </div> </footer> <dialog id="jump-to-modal" class="JumpDialog go-Modal go-Modal--md js-modal"> <form method="dialog" data-gmtc="jump to form" aria-label="Jump to Identifier"> <div class="Dialog-title go-Modal-header"> <h2>Jump to</h2> <button class="go-Button go-Button--inline" type="button" data-modal-close data-gtmc="modal button" aria-label="Close" > <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="JumpDialog-filter"> <input class="JumpDialog-input go-Input" autocomplete="off" type="text"> </div> <div class="JumpDialog-body go-Modal-body"> <div class="JumpDialog-list"></div> </div> <div class="go-Modal-actions"> <button class="go-Button" data-test-id="close-dialog">Close</button> </div> </form> </dialog> <dialog class="ShortcutsDialog go-Modal go-Modal--sm js-modal"> <form method="dialog"> <div class="go-Modal-header"> <h2>Keyboard shortcuts</h2> <button class="go-Button go-Button--inline" type="button" data-modal-close data-gtmc="modal button" aria-label="Close" > <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="go-Modal-body"> <table> <tbody> <tr><td class="ShortcutsDialog-key"> <strong>?</strong></td><td> : This menu</td> </tr> <tr><td class="ShortcutsDialog-key"> <strong>/</strong></td><td> : Search site</td> </tr> <tr><td class="ShortcutsDialog-key"> <strong>f</strong> or <strong>F</strong></td><td> : Jump to</td> </tr> <tr> <td class="ShortcutsDialog-key"><strong>y</strong> or <strong>Y</strong></td> <td> : Canonical URL</td> </tr> </tbody> </table> </div> <div class="go-Modal-actions"> <button class="go-Button" data-test-id="close-dialog">Close</button> </div> </form> </dialog> <section class="Cookie-notice js-cookieNotice"> <div>go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic. <a target=_blank href="https://policies.google.com/technologies/cookies">Learn more.</a></div> <div><button class="go-Button">Okay</button></div> </section> <script> // this will throw if the querySelector can鈥檛 find the element const gtmId = document.querySelector('.js-gtmID').dataset.gtmid; if (!gtmId) { throw new Error('Google Tag Manager ID not found'); } loadScript(`https://www.googletagmanager.com/gtm.js?id=${gtmId}`); </script> <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W8MVQXG" height="0" width="0" style="display:none;visibility:hidden"> </iframe> </noscript> <div class="js-canonicalURLPath" data-canonical-url-path="/runtime/debug@go1.23.3" hidden></div> <div class="js-playgroundVars" data-modulepath="std" data-version="v1.23.3" hidden></div> <script> loadScript('/static/frontend/unit/main/main.js') </script> <script> loadScript('/static/frontend/unit/unit.js') </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10