Debugging/it: Difference between revisions

From FreeCAD Documentation
(Created page with "LLDB produrrà alcune informazioni di inizializzazione. Il (lldb) mostra che il debugger è in esecuzione nel terminale, ora inserisci::")
mNo edit summary
Line 61: Line 61:
}}
}}


<div class="mw-translate-fuzzy">
Ora FreeCAD viene avviato. Effettuare le operazioni che causano il crash o il blocco di FreeCAD, quindi immettere 'bt' nella finestra del terminale.
Ora FreeCAD viene avviato. Effettuare le operazioni che causano il crash o il blocco di FreeCAD, quindi immettere 'bt' nella finestra del terminale.
{{Code|code=
(gdb) bt
}}

Questo genera una lunga lista che descrive esattamente ciò che il programma stava facendo quando è andato in crash o in blocco. Includere questa lista nel vostro rapporto sul problema.
</div></div> <!-- END OF COLLAPSIBLE DIV -->
</div>


{{Code|code=
{{Code|code=

Revision as of 10:01, 5 November 2019

Prova preliminare

Prima di provare il debug usare la La struttura di Test (test framework - macro) per verificare se i test standard funzionano correttamente. Se non funzionano, è possibile che l'installazione sia danneggiata.

Riga di comando

Il debug di FreeCAD è supportato da alcuni meccanismi interni. La versione a riga di comando di FreeCAD fornisce delle opzioni di supporto del debug:

Queste sono le opzioni attualmente riconosciute in FreeCAD 0.15:

Opzioni generiche:

 -v [ --version ]      Stampa una stringa della versione
 -h [ --help ]         Stampa un messaggio di aiuto
 -c [ --console ]      Avvia in modalità console
 --response-file arg   Può anche essere specificato con '@name'

Configurazione:

 -l [ --write-log ]       Scrive un file di log file in: $HOME/.FreeCAD/FreeCAD.log
 --log-file arg           A differenza di --write-log permette di scrivere il file di log in un file arbitrario
 -u [ --user-cfg ] arg    File per caricare/salvare le impostazioni dell'utente
 -s [ --system-cfg ] arg  File per caricare/salvare le impostazioni di sistema
 -t [ --run-test ] arg    Livello di Test
 -M [ --module-path ] arg Percorsi di moduli aggiuntivi
 -P [ --python-path ] arg Percorsi aggiuntivi di python

Generare un Backtrace

Se si esegue una versione sperimentale di FreeCAD ancora in fase sviluppo, essa potrebbe "bloccarsi". Si può aiutare gli sviluppatori a risolvere questi problemi fornendo loro un "backtrace". Per fare questo, è necessario eseguire un "debug build" del software. "Debug build" è un parametro che viene impostato al momento della compilazione, perciò bisogna auto-compilare FreeCAD, oppure ottenere una versione "debug" precompilata.

Per Linux

Linux Debugging →

Prerequisiti:

  • pacchetto software gdb installato
  • un debug build di FreeCAD (in questo momento disponibili solo per la compilazione da sorgenti)
  • un modello di FreeCAD che causa un crash

Passaggi:

Immettere quanto segue nella finestra del terminale:

$ cd FreeCAD/bin
$ gdb FreeCAD

LLDB produrrà alcune informazioni di inizializzazione. Il (lldb) mostra che il debugger è in esecuzione nel terminale, ora inserisci::

(gdb) handle SIG33 noprint nostop
(gdb) run

Ora FreeCAD viene avviato. Effettuare le operazioni che causano il crash o il blocco di FreeCAD, quindi immettere 'bt' nella finestra del terminale.

(gdb) bt

This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report.

(gdb) bt full

Print the values of the local variables also. This can be combined with a number to limit the number of frames shown.

Per MacOSX

MacOSX Debugging ---->

Prerequisiti:

MacOSX Debugging →

Prerequisites:

  • pacchetto software lldb installato
  • un debug build di FreeCAD
  • un modello di FreeCAD che causa un crash

Passaggi:

Immettere quanto segue nella finestra del terminale:

$ cd FreeCAD/bin
$ lldb FreeCAD

LLDB will output some initializing information. The (lldb) shows the debugger is running in the terminal, now input:

(lldb) run

Ora FreeCAD viene avviato. Effettuare le operazioni che causano il crash o il blocco di FreeCAD, quindi immettere 'bt' nella finestra del terminale.

(lldb) bt

Questo genera una lunga lista che descrive esattamente ciò che il programma stava facendo quando è andato in crash o in blocco. Includere questa lista nel vostro rapporto sul problema.

(lldb) bt

This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report.

Eliminare errori Python

Per un approccio più moderno al debug di Python, almeno su Windows, vedere questo post nel Forum.

winpdb

winpdb Debugging →

Here is an example of using Winpdb inside FreeCAD:

We need the python debugger: Winpdb. If you do not have it installed, on Ubuntu/Debian install it with:

sudo apt-get install winpdb

Now lets setup the debugger.

  1. Start Winpdb.
  2. Set the debugger password to "test": Go to menu FilePassword" and set the password.

Now we will run a test python script in FreeCAD step by step.

  1. Eseguire winpdb e impostare la password (ad esempio test)
  2. Creare un file Python con questo contenuto
import rpdb2
rpdb2.start_embedded_debugger("test")
import FreeCAD
import Part
import Draft
print "hello"
print "hello"
import Draft
points=[FreeCAD.Vector(-3.0,-1.0,0.0),FreeCAD.Vector(-2.0,0.0,0.0)]
Draft.makeWire(points,closed=False,face=False,support=None)
  1. Avviare FreeCAD e caricare il file precedente in FreeCAD.
  2. Premere F6 per eseguirlo.
  3. Ora FreeCAD non risponde perché il debugger Python è in attesa
  4. Passare alla GUI di Windpdb e cliccare su "Attach". Dopo pochi secondi appare una voce "<Input>" su cui si deve fare doppio clic.
  5. Ora in Winpdb viene visualizzato lo script attualmente in esecuzione.
  6. Impostare un break nell'ultima riga e premere F5.
  7. Ora premere F7 per entrare nel codice Python di Draft.makeWire

Visual Studio Code (VS Code)

VS Code Debugging →

Prerequisites:

  • ptvsd package need to be installed
pip install ptvsd

pypi page

Visual Studio Code documentation for remote debugging

Steps:

  • Add following code at the beginning of your script
import ptvsd
print("Waiting for debugger attach")
# 5678 is the default attach port in the VS Code debug configurations
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)
ptvsd.wait_for_attach()
  • Add a debug configuration in Visual Studio Code Debug → Add Configurations…. It should looks like this :
    "configurations": [
        {
            "name": "Python: Attacher",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        },
  • In VS Code add a breakpoint anywhere you want.
  • Launch the script in FreeCAD. FreeCAD freeze waiting for attachment.
  • In VS Code start debugging used created configuration. You should see variables in debugger area.