PageSourceSearch

https://docs.ignite.com/assets/js/295334d8.3df80969.js

js ignite.com collected 2026-10-03 23:18:24 UTC 12,815 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkmy_website=globalThis.webpackChunkmy_website||[]).push([[2201],{15680(e,n,t){t.d(n,{xA:()=>p,yg:()=>d});var i=t(96540);function a(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function r(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);n&&(i=i.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,i)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?r(Object(t),!0).forEach((function(n){a(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function o(e,n){if(null==e)return{};var t,i,a=function(e,n){if(null==e)return{};var t,i,a={},r=Object.keys(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)t=r[i],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}var g=i.createContext({}),u=function(e){var n=i.useContext(g),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},p=function(e){var n=u(e.components);return i.createElement(g.Provider,{value:n},e.children)},s={inlineCode:"code",wrapper:function(e){var n=e.children;return i.createElement(i.Fragment,{},n)}},c=i.forwardRef((function(e,n){var t=e.components,a=e.mdxType,r=e.originalType,g=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),c=u(t),d=a,y=c["".concat(g,".").concat(d)]||c[d]||s[d]||r;return t?i.createElement(y,l(l({ref:n},p),{},{components:t})):i.createElement(y,l({ref:n},p))}));function d(e,n){var t=arguments,a=n&&n.mdxType;if("string"==typeof e||a){var r=t.length,l=new Array(r);l[0]=c;var o={};for(var g in n)hasOwnProperty.call(n,g)&&(o[g]=n[g]);o.originalType=e,o.mdxType="string"==typeof e?e:a,l[1]=o;for(var u=2;u<r;u++)l[u]=t[u];return i.createElement.apply(null,l)}return i.createElement.apply(null,t)}c.displayName="MDXCreateElement"},89724(e,n,t){t.r(n),t.d(n,{assets:()=>g,contentTitle:()=>l,default:()=>s,frontMatter:()=>r,metadata:()=>o,toc:()=>u});var i=t(58168),a=(t(96540),t(15680));const r={description:"Debugging your Cosmos SDK blockchain"},l="Debugging a chain",o={unversionedId:"guide/debug",id:"version-v0.26/guide/debug",title:"Debugging a chain",description:"Debugging your Cosmos SDK blockchain",source:"@site/versioned_docs/version-v0.26/02-guide/08-debug.md",sourceDirName:"02-guide",slug:"/guide/debug",permalink:"/v0.26/guide/debug",draft:!1,tags:[],version:"v0.26",sidebarPosition:8,frontMatter:{description:"Debugging your Cosmos SDK blockchain"},sidebar:"tutorialSidebar",previous:{title:"Write Test Files",permalink:"/v0.26/guide/interchange/tests"},next:{title:"Running inside a Docker container",permalink:"/v0.26/guide/docker"}},g={},u=[{value:"Debug Command",id:"debug-command",level:2},{value:"Debug Server",id:"debug-server",level:2},{value:"Debugging Clients",id:"debugging-clients",level:2},{value:"Gdlv: Multiplatform Delve UI",id:"gdlv-multiplatform-delve-ui",level:3},{value:"Visual Studio Code",id:"visual-studio-code",level:3},{value:"Example: Debugging a Blockchain App",id:"example-debugging-a-blockchain-app",level:2}],p={toc:u};function s(e){let{components:n,...t}=e;return(0,a.yg)("wrapper",(0,i.A)({},p,t,{components:n,mdxType:"MDXLayout"}),(0,a.yg)("h1",{id:"debugging-a-chain"},"Debugging a chain"),(0,a.yg)("p",null,"Ignite chain debug command can help you find issues during development. It uses\n",(0,a.yg)("a",{parentName:"p",href:"https://github.com/go-delve/delve"},"Delve")," debugger which enables you to\ninteract with your blockchain app by controlling the execution of the process,\nevaluating variables, and providing information of thread / goroutine state, CPU\nregister state and more."),(0,a.yg)("h2",{id:"debug-command"},"Debug Command"),(0,a.yg)("p",null,"The debug command requires that the blockchain app binary is build with\ndebugging support by removing optimizations and inlining. A debug binary is\nbuilt by default by the ",(0,a.yg)("inlineCode",{parentName:"p"}
1,"ignite chain serve")," command or can optionally be\ncreated using the ",(0,a.yg)("inlineCode",{parentName:"p"},"--debug")," flag when running ",(0,a.yg)("inlineCode",{parentName:"p"},"ignite chain init")," or ",(0,a.yg)("inlineCode",{parentName:"p"},"ignite\nchain build")," sub-commands."),(0,a.yg)("p",null,"To start a debugging session in the terminal run:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite chain debug\n")),(0,a.yg)("p",null,"The command runs your blockchain app in the background, attaches to it and\nlaunches a terminal debugger shell:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"Type 'help' for list of commands.\n(dlv)\n")),(0,a.yg)("p",null,"At this point the blockchain app blocks execution, so you can set one or more\nbreakpoints before continuing execution."),(0,a.yg)("p",null,"Use the\n",(0,a.yg)("a",{parentName:"p",href:"https://github.com/go-delve/delve/blob/master/Documentation/cli/README.md#break"},"break"),"\n(alias ",(0,a.yg)("inlineCode",{parentName:"p"},"b"),") command to set any number of breakpoints using, for example the\n",(0,a.yg)("inlineCode",{parentName:"p"},"<filename>:<line>")," notation:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"(dlv) break x/hello/client/cli/query_say_hello.go:14\n")),(0,a.yg)("p",null,"This command adds a breakpoint to the ",(0,a.yg)("inlineCode",{parentName:"p"},"x/hello/client/cli/query_say_hello.go"),"\nfile at line 14."),(0,a.yg)("p",null,"Once all breakpoints are set resume blockchain execution using the\n",(0,a.yg)("a",{parentName:"p",href:"https://github.com/go-delve/delve/blob/master/Documentation/cli/README.md#continue"},"continue"),"\n(alias ",(0,a.yg)("inlineCode",{parentName:"p"},"c"),") command:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"(dlv) continue\n")),(0,a.yg)("p",null,"The debugger will launch the shell and stop blockchain execution again when a\nbreakpoint is triggered."),(0,a.yg)("p",null,"Within the debugger shell use the ",(0,a.yg)("inlineCode",{parentName:"p"},"quit")," (alias ",(0,a.yg)("inlineCode",{parentName:"p"},"q"),") or ",(0,a.yg)("inlineCode",{parentName:"p"},"exit")," commands to stop\nthe blockchain app and exit the debugger."),(0,a.yg)("h2",{id:"debug-server"},"Debug Server"),(0,a.yg)("p",null,"A debug server can optionally be started in cases where the default terminal\nclient is not desirable. When the server starts it first runs the blockchain\napp, attaches to it and finally waits for a client connection. The default\nserver address is ",(0,a.yg)("em",{parentName:"p"},"tcp://127.0.0.1:30500")," and it accepts both JSON-RPC or DAP\nclient connections."),(0,a.yg)("p",null,"To start a debug server use the following flag:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite chain debug --server\n")),(0,a.yg)("p",null,"To start a debug server with a custom address use the following flags:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite chain debug --server --server-address 127.0.0.1:30500\n")),(0,a.yg)("p",null,"The debug server stops automatically when the client connection is closed."),(0,a.yg)("h2",{id:"debugging-clients"},"Debugging Clients"),(0,a.yg)("h3",{id:"gdlv-multiplatform-delve-ui"},"Gdlv: Multiplatform Delve UI"),(0,a.yg)("p",null,(0,a.yg)("a",{parentName:"p",href:"https://github.com/aarzilli/gdlv"},"Gdlv")," is a graphical frontend to Delve for\nLinux, Windows and macOS."),(0,a.yg)("p",null,"Using it as debugging client is straightforward as it doesn't require any\nconfiguration. Once the debug server is running and listening for client\nrequests connect to it by running:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"gdlv connect 127.0.0.1:30500\n")),(0,a.yg)("p",null,"Setting breakpoints and continuing execution is done in the same way as Delve,\nby using the ",(0,a.yg)("inlineCode",{parentName:"p"},"break")," and ",(0,a.yg)("inlineCode",{parentName:"p"},"continue")," commands."),(0,a.yg)("h3",{id:"visual-studio-code"},"Visual Studio Code"),(0,a.yg)("p",null,"Using ",(0,a.yg)("a",{parentName:"p",href:"https://code.visualstudio.com/"},"Visual Studio Code")," as debugging client\nrequires an initial configuration to allow it to connect to the debug server."),(0,a.yg)("p",null,"Make sure that the ",(0,a.yg)("a",{parentName:"p",href:"https://code.visualstudio.com/docs/languages/go"},"Go"),"\nextension is installed."),(0,a.yg)("p",null,"VS Code debugging is configured using the ",(0,a.yg)("inlineCode",{parentName:"p"},"launch.json")," file which is usually\nlocated inside the ",(0,a.yg)("inlineCode",{parentName:"p"},".vscode")," folder in your workspace."),(0,a.yg)("p",null,"You can use the following launch configuration to set up VS Code as debugging\nclient:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre",className:"language-json",metastring:"title=launch.json",title:"launch.json"},'{\n    "version": "0.2.0",\n    "configurations": [\n        {\n            "name": "Connect to Debug Server",\n            "type": "go",\n            "request": "attach",\n            "mode": "remote",\n            "remotePath": "${workspaceFolder}",\n            "port": 30500,\n            "host": "127.0.0.1"\n        }\n    ]\n}\n')),(0,a.yg)("p",null,"Alternatively it's possible to create a custom ",(0,a.yg)("inlineCode",{parentName:"p"},"launch.json"),' file from the "Run\nand Debug" panel. When prompted choose the Go debugger option labeled "Go:\nConnect to Server" and enter the debug host address and then the port number.'),(0,a.yg)("h2",{id:"example-debugging-a-blockchain-app"},"Example: Debugging a Blockchain App"),(0,a.yg)("p",null,"In this short example we will be using Ignite CLI to create a new blockchain and\na query to be able to trigger a debugging breakpoint when the query is called."),(0,a.yg)("p",null,"Create a new blockchain:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite scaffold chain hello\n")),(0,a.yg)("p",null,"Scaffold a new query in the ",(0,a.yg)("inlineCode",{parentName:"p"},"hello")," directory:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite scaffold query say-hello name --response name\n")),(0,a.yg)("p",null,"The next step initializes the blockchain's data directory and compiles a debug\nbinary:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite chain init --debug\n")),(0,a.yg)("p",null,"Once the initialization finishes launch the debugger shell:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"ignite chain debug\n")),(0,a.yg)("p",null,"Within the debugger shell create a breakpoint that will be triggered when the\n",(0,a.yg)("inlineCode",{parentName:"p"},"SayHello")," function is called and then continue execution:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"(dlv) break x/hello/keeper/query_say_hello.go:12\n(dlv) continue\n")),(0,a.yg)("p",null,"From a different terminal use the ",(0,a.yg)("inlineCode",{parentName:"p"},"hellod")," binary to call the query:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},"hellod query hello say-hello bob\n")),(0,a.yg)("p",null,"A debugger shell will be launched when the breakpoint is triggered:"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},'     7:     "google.golang.org/grpc/codes"\n     8:     "google.golang.org/grpc/status"\n     9:     "hello/x/hello/types"\n    10: )\n    11:\n=>  12: func (k Keeper) SayHello(goCtx context.Context, req *types.QuerySayHelloRequest) (*types.QuerySayHelloResponse, error) {\n    13:     if req == nil {\n    14:         return nil, status.Error(codes.InvalidArgument, "invalid request")\n    15:     }
1\n    16:\n    17:     ctx := sdk.UnwrapSDKContext(goCtx)\n')),(0,a.yg)("p",null,"From then on you can use Delve commands like ",(0,a.yg)("inlineCode",{parentName:"p"},"next")," (alias ",(0,a.yg)("inlineCode",{parentName:"p"},"n"),") or ",(0,a.yg)("inlineCode",{parentName:"p"},"print"),"\n(alias ",(0,a.yg)("inlineCode",{parentName:"p"},"p"),") to control execution and print values. For example, to print the\n",(0,a.yg)("em",{parentName:"p"},"name")," argument value use the ",(0,a.yg)("inlineCode",{parentName:"p"},"print"),' command followed by "req.Name":'),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre"},'(dlv) print req.Name\n"bob"\n')),(0,a.yg)("p",null,"Finally, use ",(0,a.yg)("inlineCode",{parentName:"p"},"quit")," (alias ",(0,a.yg)("inlineCode",{parentName:"p"},"q"),") to stop the blockchain app and finish the\ndebugging session."))}s.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.