[Read MFiX source code] Fanwai: How to use gdb to debug mfix program? And use Visual studio code to visualize the debug

@ [TOC]
## The premise is to prepare
linux / windows with gdb installed

If not, download one under apt-get under ubantu, generally comes with
windows to install mingw64 (be careful not to make mistakes 64-bit and 32-bit cannot be universal)

----
I use the Ubantu 16.04 virtual machine
using mfix-19.3.1

## 方法
### 1. Compile your solver

At the terminal, type
`` `bash
build_mfixsolver --batch" FCFLAGS = -g -O0 "-j 4`
``
After completion, an executable file named mfixsolver will appear

Parameter explanation:
--batch means that you can only run mfix (non-GUI) from the command line. Only in this way can the executable file
FCFLAGS stand for the parameter passed into the compiler (the default is not specified by gfortran)
-g means output debug Information, this information will be received by gdb
-O0 means no compilation optimization. Only if this parameter is added, the statements will be executed one by one in order, otherwise you will find that the statements of the program are skipping, and then get there after a while.

### 2. Load your compiled program gdb
`` `bash
gdb mfixsolver
` ``
then the terminal will enter inside gdb

### 3. Running and viewing the source code in gdb
Entering
`` `bash
list or
l```
will display a few lines of source code

Enter
`` `bash
RUN -f gas_and_solid_Yin.mfx
` ``
will run the program, which gas_and_solid_Yin.mfx replaced with the name of your own .mfx of

Control C cannot terminate the program here.
To terminate the program, use == control + z ==

See
[https://www.cnblogs.com/HKUI/p/8955443.html](https://www.cnblogs.com/HKUI/p/8955443.html) for common usage of gbd


## Summary of common errors
1. It will appear if it is compiled into pure command line mode with --batch

`` shell `
not in Executable format: File format not Recognized
` ``
This is because the GUI compiler is actually produced by a shell document, a statement which it: pointing python
visible mfix of the GUI is a set of python shell program

2. If no parameters are given when running in gdb -f gas_and_solid_Yin.mfx
`` `
***************************** *****************************************
From: mfix.f
Error 1000: Input data file does not exist: mfix.dat
Aborting.
*************************************** *******************************
`` `
It is very simple, without specifying the name of the deck file, the name is automatically determined as mfix. dat, you can only use this name in the old version

## Advanced: Visualizing
gdb debugging with VS code can basically meet most of the needs
but can not visualize the interruption point. It is inconvenient to
use vs code to debug like Visual Studio.
== Note : Still need to compile mfixsolver ==

### 1 Preparation: Install a plugin to
download a visual studio code

Search for the plugin in the expansion tab on the left

== Install a plugin named morden fortran ==== Install a plugin
named C / C ++
==== Install a plugin named fortran breakpoint ==

You can also install the Chinese plugin, which is a localization of VS CODE
! [Insert picture description here] (https://img-blog.csdnimg.cn/20200421151000815.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk, shadow_10, text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80Mzk0MDMxNA ==, size_16, color_FFFFFF, t_70)


### 2 Configure launch.json to
click the debug button on the left sidebar, then click the small gear, and finally click C ++ (GDB / LLDB)
as shown
in the picture! [Insert picture description here] (https: //imgconvert.csdnimg. cn / aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8vdXBsb2FkX2ltYWdlcy84NDY1NzMxLTBiNzdmNjIwNjE4Y2JhZmMucG5n? x-oss-process = image /)

== After that, the launch.json file will appear in your .vscode folder (you can delete this file at any time if the configuration is wrong, and then re-operate) == The
content of the file is
`` `javascript
{
// Use IntelliSense to understand related attributes.
// Hover to see the description of existing properties.
// For more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb ) Start ",
" type ":" cppdbg ",
" request ":" launch ",
" program ":" Enter the program name, for example $ {workspaceFolder} /a.out ",
" args ": [],
" stopAtEntry " : false,
"cwd": "$ {workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode":




"ignoreFailures": to true
}
]
}
]
}
`` `
The
" program ":" Enter the name of the program, for example, $ {workspaceFolder} /a.out ",
the position of the second row quotes replace your mfixsolver position ( Full path) For
example, mine is
/ home / cl / MFiX_Cases / git_sync / Yin_0413_git_sync_case / mfixsolver

stopAtEntry can be changed to true, which means to pause after entering the program.
This is the modified launch.json

`` `javascript
{
// Use IntelliSense to understand related properties.
// Hover to see the description of existing properties.
// For more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb ) Start ",
" type ":" cppdbg ",
" request ":" launch ",
" program ":" $ {workspaceFolder} / mfixsolver ",
" args ": [],
" stopAtEntry ": true,
" cwd ": "$ {workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"






}
```


### 3 Run and debug
Press F5 to run and debug,
a small tool box for debugging will appear in the upper right corner
! [Insert picture description here] (https://img-blog.csdnimg.cn/20200421003230396.png)
step by step (F10) means not to enter subroutines / functions,
F11 is to enter every subroutine, and running
out sentence by sentence means jumping out of the current subroutine


How to break the point
! [Insert picture description here] (https://img-blog.csdnimg.cn/20200421150520249.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4zkMdx0, color_FFFFFF, t_70)
Click on the blank space to the left of the line number, a small red dot will appear. Is that the breakpoint
F5 runs to the next breakpoint

### Error summary
#### Question 1 error
there is a problem to be solved, just can not specify -f .mfx file error
`` `
****************** ************************************************** **
From: mfix.f
Error 1000: Input data file does not exist: mfix.dat
Aborting.
**************************** ******************************************
`` `Nothing
has been found so far Solution, but rename the .mfx file to mfix.dat.
After all, it ’s a name, it does n’t matter.

#### Problem 2 Quickly delete
run_type = new when restarting, there must not be any results that have been produced, you must empty the folder every time to run

It is very troublesome to manually delete a bunch of things every time you start, use the terminal code
`` `
rm -r * .RES * .SP * * .pvd * .csv VTK BACKUP_RES * .LOG * .OUT * .TXT * .vtu * .vtp
`` `

Or define it in ~ / .bashrc,
copy the code to the last line, then restart the terminal, run
`` `
alias mfixclean =" rm -r * .RES * .SP * * .pvd * .csv VTK BACKUP_RES * .LOG * .OUT * .TXT * .vtu * .vtp "
` "
so that every time you delete only need to run mfixclean

#### Problem 3 Unable to
breakpoint / run the next step The main reason is that the fortran breakpoint plugin is not installed

#### Question 4 Can't find mfixsolver
vs code just visualize debugging. So I still have to compile it myself.

You need to compile mfixsolver
`` `bash
build_mfixsolver --batch" FCFLAGS = -g -O0 "-j 4`
``

Guess you like

Origin www.cnblogs.com/chunleili/p/gdb_debug_MFiX.html