Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
about_Debuggers
DESCRIZIONE BREVE
Descrive il debugger di Windows PowerShell.
DESCRIZIONE DETTAGLIATA
Per debug si intende il processo attraverso il quale uno script viene
esaminato durante la sua esecuzione allo scopo di identificare e
correggere eventuali errori presenti nelle istruzioni. Il debugger di
Windows PowerShell è stato progettato per consentire l'esame e
l'identificazione degli errori e delle inefficienze eventualmente
presenti negli script.
[DBG]: PS (get-location)>>>
Ad esempio:
Debug e ambito
L'accesso al debugger non modifica l'ambito nel quale viene
eseguito, tuttavia quando si raggiunge un punto di interruzione
in uno script, ci si sposta nell'ambito dello script. L'ambito dello
script è un elemento figlio dell'ambito nel quale è stato eseguito il
debugger.
gv -s 0
Ad esempio:
function test-cmdlet
{
begin
{
write-output "Begin"
}
process
{
write-output "Process"
}
end
{
write-output "End"
}
}
C:\PS> test-cmdlet
Begin
Entering debug mode. Use h or ? for help.
test-cmdlet
[DBG]: C:\PS> c
Process
Entering debug mode. Use h or ? for help.
test-cmdlet
[DBG]: C:\PS> c
End
Entering debug mode. Use h or ? for help.
test-cmdlet
[DBG]: C:\PS>
Esempi
Questo script di test rileva la versione del sistema operativo e
visualizza un messaggio appropriato. Sono inclusi una funzione, una
chiamata di funzione e una variabile.
$scriptname = $MyInvocation.MyCommand.Path
psversion
"Done $scriptname."
Column : 0
Line : 1
Action :
Enabled : True
HitCount : 0
Id : 0
Script : C:\ps-test\test.ps1
ScriptName : C:\ps-test\test.ps1
PS C:\ps-test> .\test.ps1
DBG> s
test.ps1:11 $scriptname = $MyInvocation.MyCommand.Path
DBG> $scriptname
DBG>
DBG> s
test.ps1:12 psversion
DBG> $scriptname
C:\ps-test\test.ps1
DBG> o
Windows Powershell 2.0
Have you run a background job today (start-job)?
test.ps1:13 "Done $scriptname"
Done C:\ps-test\test.ps1
PS C:\ps-test>
PS C:\ps-test> .\test.ps1
Hit Variable breakpoint on 'C:\ps-test\test.ps1:$scriptname'
(Write access)
DBG> $scriptname
DBG>
DBG> $scriptname
C:\ps-test\test.ps1
DBG> s
test.ps1:12 psversion
DBG> v
Windows Powershell 2.0
Have you run a background job today (start-job)?
test.ps1:13 "Done $scriptname"
Il comando Step-Over esegue la funzione, quindi visualizza in
anteprima l'istruzione successiva nello script che stampa la
riga finale.
C:\ps-test>
PS C:\ps-test> .\test.ps1
Hit Command breakpoint on 'C:\ps-test\test.ps1:psversion'
test.ps1:12 psversion
DBG>
PS C:\ps-test> .\test.ps1
Hit Command breakpoint on 'C:\ps-test\test.ps1:psversion'
test.ps1:12 psversion
DBG> k
2: prompt
1: .\test.ps1: $args=[]
0: prompt: $args=[]
Ad esempio, digitare:
VEDERE ANCHE
Disable-PsBreakpoint
Get-PsBreakpoint
Remove-PsBreakpoint
Set-PsBreakpoint
Set-PsDebug
Set-Strictmode
Write-Debug
Write-Verbose
Enable-PsBreakpoint
Get-PsCallStack