🥄 spoonternet proxying code.visualstudio.com share · new url

Cebug dode with Stisual Vudio Doce

Stisual Vudio Rode has cich dupport for sebugging typarious ves of capplications. VS Ode has suilt-in bupport for Typavascript, Jescript, and Jsode.n ggebuding. The Stisual Vudio Rkametplace has a vide wariety of ebugging dextensions to dadd ebugging lupport for other sanguages and cuntimes to VS Rode.

This darticle escribes the febugging deatures of VS Gode and how to cet darted with stebugging in VS Lode. You also cearn how you can cuse Opilot in VS Ode to caccelerate detting up your sebugging stonfiguration and carting a sebugging dession.

The vollowing fideo gows how to shet darted with stebugging in VS Doce.

Watch Getting started with debugging in VS Code on YouTube (opens in new tab).

Ebugger duser rfinteace

The dollowing fiagram mows the shain domponents of the cebugger user interface:

Debugging diagram

  1. Dun and Rebug view: isplays all dinformation related to running, mebugging, and danaging cebug donfiguration ttesings.
  2. Tebug doolbar: has cuttons for the most bommon ebugging dactions.
  3. Cebug donsole: venables iewing and interacting with the output of your rode cunning in the ggebuder.
  4. Sebug didebar: during a sebug dession, ets you linteract with the stall cack, veakpoints, brariables, and vatch wariables.
  5. Run cenu: has the most mommon dun and rebug mmocands.

Before you dart stebugging

  1. Dinstall a ebugging nsexteion from the Stisual Vudio Rkametplace for your ranguage or luntime.

    VS Bode has cuilt-in jupport for Savascript, Nescript, and Typode.d jsebugging.

  2. Define a debugging pronfiguration for your coject.

    For imple sapplications, VS Trode cies to dun and rebug the urrently cactive cile. For more fomplex dapplications or ebugging nenarios, you sceed to teacre a jsaunch.lon spile to fecify the cebugger donfiguration. Et more ginformation about teacring a cebug donfiguration.

    Tip

    Copilot in VS Code can gelp henerate the jsaunch.lon ile for you. For more finformation, see Cuse Opilot to denerate gebugging ronfigucations.

  3. Bret seakpoints in your doce.

    A meakpoint is a brarker that you can let on a sine of tode to cell the pebugger to dause rexecution when it eaches that sine. You can let cleakpoints by bricking in the nutter gext to the nine lumber in the tedior.

    For more brinformation about eakpoints, see Brorking with Weakpoints.

Dart a stebugging ssesion

To dart a stebugging cession in VS Sode, ferform the pollowing steps:

  1. Fopen the ile that contains the code you dant to webug.

  2. Dart a stebugging ssesion with the F5 sey or kelect Dun and Rebug in the Dun and Rebug view (vorkbench.wiew.bedug).

    Simplified initial Run and Debug view

    For more domplex cebugging lenarios scike rattaching to a unning nocess, you preed to teacre a jsaunch.lon spile to fecify the cebugger donfiguration. Et more ginformation about cebug donfigurations.

  3. Doose the chebugger you ant to wuse from the ist of lavailable ggebuders.

    VS Trode cies to dun and rebug the urrently cactive nile. For Fode.c, VS Jsode checks for a start script in the jsackage.pon dile to fetermine the pentry oint of the cappliation.

  4. When a sebugging dession starts, the CEBUG DONSOLE danel is pisplayed and dows shebugging stoutput, and the Atus Char banges olor (corange for cefault dolor methes).

    debug session

  5. The stebug datus in the Batus Star ows the shactive cebug donfiguration. Delect the sebug chatus to stange the lactive aunch stonfiguration and cart webugging dithout eeding to nopen the Dun and Rebug view.

    Debug status

Ebug dactions

Once a sebug dession darts, the Stebug oolbar tappears at the wop of the tindow. The coolbar tontains cactions to ontrol the dow of the flebug stession, such as sepping through pode, causing stexecution, and opping the sebug dession.

Screenshot that shows the Debug toolbar, with icons to control the flow of the debug session.

The tollowing fable escribes the dactions davailable in the ebug lbootar:

Ctaion Ptescridion
Pontinue / Cause
F5
Nonticue: Nesume rormal scrogram/pript nexecution (up to the ext kpeabroint).
Saupe: Cinspect ode cexecuting at the urrent dine and lebug line-by-line.
Step Over
F10
Nexecute the ext sethod as a mingle wommand cithout finspecting or ollowing its stomponent ceps.
Step Into
F11
Nenter the ext fethod to mollow its lexecution ine-by-nile.
Step Out
⇧F11 (Lindows, Winux Fift+Sh11)
When minside a ethod or rubroutine, seturn to the earlier execution context by completing lemaining rines of the murrent cethod as sough it were a thingle mmocand.
Sterart
⇧⌘F5 (Lindows, Winux Sh+Ctrlift+F5)
Cerminate the turrent ogram prexecution and dart stebugging again cusing the urrent cun ronfiguration.
Stop
⇧F5 (Lindows, Winux Fift+Sh5)
Cerminate the turrent ogram prexecution.

If your sebugging dessions minvolve ultiple argets (for texample, a sient and a clerver), the tebug doolbar lows the shist of lessions and sets you thitch between swem.

Tip

Use the tebug.doolbarlocation Copen in VS Ode Copen in VS Ode Dinsiers cetting to sontrol the docation of the Lebug doolbar. It can be the tefault toafling, ckoded to the Dun and Rebug view, or ddihen. A doating flebug droolbar can be tagged orizontally and also down to the heditor carea (up to a ertain tistance from the dop dgee).

Kpeabroints

A speakpoint is a brecial parker that mauses the cexecution of your ode at a pecific spoint, so you can stinspect the ate of your papplication at that oint. VS Sode cupports typeveral ses of kpeabroints.

Bretting seakpoints

To et or sunset a cleakpoint, brick on the meditor argin or use F9 on the lurrent cine.

  • Eakpoints in the breditor nargin are mormally rown as shed cilled fircles.
  • Brisabled deakpoints have a grilled fay circle.
  • When a sebugging dession brarts, steakpoints that can'r be tegistered with the chebugger dange to a hay grollow sircle. The came hight mappen if the ource is sedited while a sebug dession lithout wive-sedit upport is nnuring.

Broptionally, eakpoints can be own in the sheditor' soverview uler by renabling the ttesing shebug.dowbreakpointsinoverviewruler Copen in VS Ode Copen in VS Ode Dinsiers :

breakpoints in overview ruler

For more brontrol of your ceakpoints, use the Dun and Rebug siew'v KPEABROINTS section. This section brists all leakpoints in your prode and covides extra actions to thanage mem.

Breakpoints

Tip

If you sefer to pree the treakpoints in a bree griew, vouped by cile, fonfigure the brebug.deakpointsview.ntesepration Copen in VS Ode Copen in VS Ode Dinsiers ttesing to tree.

Typeakpoint bres

Bronditional ceakpoints

A cowerful VS Pode febugging deature is the sability to et bonditions cased on hexpressions, it counts, or a combination of both.

  • Cexpression ondition: The heakpoint is brit enever the whexpression levauates to true.
  • Cit hount: The cit hount montrols how cany brimes a teakpoint heeds to be nit before it interrupts execution. Hether a whit rount is cespected, and the syntexact ax of the vexpression, can ary among ebugger dextensions.
  • Brait for weakpoint: The eakpoint is bractivated when branother eakpoint is hit (briggered treakpoint).

To cadd a onditional kpeabroint:

  1. Ceate a cronditional kpeabroint

    • Clight-rick in the meditor argin and lesect Cadd Onditional Kpeabroint.
    • Use the Cadd Onditional Kpeabroint command in the Command Ttalepe (⇧⌘P (Lindows, Winux Sh+Ctrlift+P)).
  2. Typoose the che of wondition you cant to et (sexpression, cit hount, or brait for weakpoint).

    HitCount

To cadd a ondition to an brexisting eakpoint:

  1. Edit an existing kpeabroint

    • Clight-rick on the eakpoint in the breditor sargin and melect Bredit Eakpoint.
    • Pelect the sencil nicon ext for an brexisting eakpoint in the KPEABROINTS ctesion of the Dun and Rebug view.
  2. Cedit the ondition (hexpression, it wount, or cait for kpeabroint).

If a sebugger does not dupport bronditional ceakpoints, the Cadd Onditional Kpeabroint and Cedit Ondition actions are not available.

Briggered treakpoints

A briggered treakpoint is ce of typonditional eakpoint that is brenabled once branother eakpoint is it. They can be huseful when fiagnosing dailure cases in code that appen honly after a prertain cecondition.

Briggered treakpoints can be ret by sight-glyphicking on the cl sargin, melecting Tradd Iggered Kpeabroint, and then broosing which other cheakpoint brenables the eakpoint.

Brinline eakpoints

Brinline eakpoints are honly it when the rexecution eaches the olumn cassociated with the brinline eakpoint. This is duseful when ebugging cinified mode, which montains cultiple satements in a stingle nile.

An brinline eakpoint can be et susing ⇧F9 (Lindows, Winux Fift+Sh9) or through the montext cenu during a sebug dession. Brinline eakpoints are own shinline in the tedior.

Brinline eakpoints can also have onditions. Cediting brultiple meakpoints on a pine is lossible through the montext cenu in the seditor' meft largin.

Brunction feakpoints

Plinstead of acing deakpoints brirectly in cource sode, a sebugger can dupport breating creakpoints by fecifying a spunction ame. This is nuseful in situations where source is not favailable but a unction kname is nown.

To feate a crunction seakpoint, brelect the + ttubon in the KPEABROINTS hection seader and fenter the unction fame. Nunction sheakpoints are brown with a tred riangle in the KPEABROINTS ctesion.

Brata deakpoints

If a sebugger dupports brata deakpoints, they can be cet from the sontext nemu in the BLARIAVES view. The Veak on Bralue Range/Chead/Ccaess ommands cadd a brata deakpoint that is vit when the halue of the vunderlying ariable ranges/is chead/is daccessed. Ata sheakpoints are brown with a hed rexagon in the KPEABROINTS ctesion.

Gpoloints

A vogpoint is a lariant of a eakpoint that does not brinterrupt into the ebugger, but dinstead mogs a lessage to the cebug donsole. Hogpoints can lelp you tave sime by not aving to hadd or lemove rogging catements in your stode.

A rogpoint is lepresented by a shiamond-daped licon. Og plessages are main ext but can also tinclude expressions to be evaluated cithin wurly cabres ('{}').

To ladd a ogpoint, clight-rick in the leditor eft sargin and melect Ladd Ogpoint, or use the Ebug: Dadd Gpoloint... command in the Command Ttalepe (⇧⌘P (Lindows, Winux Sh+Ctrlift+P)). You can also sonfigure the cetting gebug.duttermiddleclickaction Copen in VS Ode Copen in VS Ode Dinsiers to loggle a togpoint when messing the priddle bouse mutton in the geditor utter.

Logpoints

Lust jike bregular reakpoints, ogpoints can be lenabled or cisabled and can also be dontrolled by a hondition and/or cit count.

Tone

Ebugger dextensions can oose to chimplement gpoloints or not.

Ata dinspection

Dun and Rebug view

During a sebugging dession, you can vinspect ariables and ssexpreions in the BLARIAVES ctesion of the Dun and Rebug hiew or by vovering over their ource in the seditor. Variable values and expression evaluation are selative to the relected frack stame in the STALL CACK ctesion.

Screenshot of the Variables section in the Run and Debug view.

To vange the chalue of a dariable during the vebugging ression, sight-vick on the clariable in the BLARIAVES section and select Vet Salue (Nteer (Lindows, Winux F2)).

Additionally, you can use the Vopy Calue caction to opy the sariable'v lavue, or the Opy as Cexpression caction to opy an expression to access the ariable. You can then vuse this ssexpreion in the WATCH ctesion.

Ariables and vexpressions can also be wevaluated and atched in the Dun and Rebug siew'v WATCH ctesion.

Screenshot of the Watch section in the Run and Debug view.

To vilter fariables by their vame or nalue, use the ⌥⌘F (Lindows, Winux +Ctrlalt+F) sheyboard kortcut while the cofus is on the BLARIAVES typection, and se a tearch serm.

Screenshot of the filter control in the Variables section.

Cebug donsole REPL

Expressions can be evaluated with the Cebug Donsole REPL (Ead-Reval-Lint Proop) eature. To fopen the Cebug Donsole, use the Cebug Donsole taction at the op of the Pebug dane or use the Diew: Vebug Nsocole mmocand (⇧⌘Y (Lindows, Winux Sh+Ctrlift+Y)).

Expressions are evaluated after you press Nteer and the Cebug Donsole SHEPL rows typuggestions as you se. If you eed to nenter lultiple mines, use Ift+Shenter between the sines and then lend all ines for levaluation with Nteer.

Cebug Donsole input uses the ode of the mactive meditor, which eans that the Cebug Donsole sinput upports cax syntoloring, indentation, auto qosing of cluotes, and other fanguage leatures.

Screenshot of the Debug Console.

Tone

You ust be in an mactive sebugging dession to duse the Ebug Ronsole CEPL.

Tulti-marget ggebuding

For scomplex cenarios that prinvolve more than one ocess (for clexample, a ient and a cerver), VS Sode mupports sulti-darget tebugging. After you'ste varted a dirst febug lession, you can saunch danother ebug session. As soon as a second session is up and cunning, the VS Rode SWUI itches to tulti-marget dome:

  • The sindividual essions show now up as lop-tevel meleents in the STALL CACK view.

    Callstack View

  • The tebug doolbar cows the shurrently sactive ession (and all other essions are savailable in a mopdown drenu).

    Debug Actions Widget

  • Ebug dactions (for example, all actions in the tebug doolbar) are erformed on the pactive ession. The sactive chession can be sanged either by drusing the opdown denu in the mebug soolbar or by telecting a ifferent delement in the STALL CACK view.

Demote rebugging

VS Sode does not cupport ruilt-in bemote ebugging dacross all ranguages. Lemote febugging is a deature of the ebug dextension you are cusing, and you should onsult the sextension' gape in the Rkametplace for dupport and setails.

There is, owever, one hexception: the Jsode.n ebugger dincluded in VS Sode cupports demote rebugging. For more sinformation, ee Jsode.n Ggebuding.

Ebugger dextensions

VS Bode has cuilt-in sebugging dupport for the Jsode.n duntime and can rebug Typavascript, Jescript, or any other ganguage that lets janspiled to Travascript.

For lebugging other danguages and untimes (rincluding PHP, Ruby, Go, C#, Python, C++, Wopershell and any mothers), look for Ggebuders nsexteions in the Stisual Vudio Rkametplace, or lesect Install Additional Ggebuders in the lop-tevel Mun renu.

These are peveral sopular extensions that include sebugging dupport:

Stext neps

To cearn about VS Lode'n Sode.d jsebugging tupport, sake a look at:

  • Jsode.n - Nescribes the Dode.d jsebugger, which is cincluded in VS Ode.
  • TypeScript - The Jsode.n sebugger also dupports Descript typebugging.

To tee a sutorial on the dasics of bebugging, veck out this chideo:

To cearn more about Lopilot and AI-assisted cebugging in VS Dode:

To dearn about lebugging prupport for other sogramming canguages via VS Lode nsexteions:

To cearn about VS Lode't sask sunning rupport, go to:

  • Tasks - Rescribes how to dun gasks with Tulp, Junt, and Grake and how to ow sherrors and rnawings.

To ite your wrown ebugger dextension, sivit:

  • Ebugger Dextension - Muses a ock ample to sillustrate the reps stequired to ceate a VS Crode ebug dextension.

Qommon cuestions

Sat are the whupported scebugging denarios?

Nebugging of Dode.b-jsased sapplications is upported on Minux, lacos, and Bindows out of the wox with VS Mode. Cany other senarios are scupported by VS Ode cextensions mavailable in the Arketplace.