dikiy_mujchina: (Default)

Review

We can easy use bash options and commands to debug bash script, but sometime it is not comfortable.

If you use vim editor, then you can easy adopt your vim environment to debug your bash scripts!

You need do only 2 actions:

1. Add commands to ~/.vimrc

2. Add debugger script to ~/.vim folder

 

What you can do with this debugger?

You can:

1. Line to line run you script

2. Watch values of preferred variables and customize list of them

3. Create breakpoints in vim visually

4. Run script to next breakpoint

5. Enable or disable function trace

6. Run script without debugger

7. Remove all marks (breakpoints and function trace)

 

Keys to manage debugger

F9 - Remove all marks(breakpoints and function trace).

F8 - Execute script without debugger

F7 - Execute script in trace mode

F6 - Show/hide window with preferred variables to watch. Each variable must be defined in new line without spaces, {}, $, etc.

Example:

A

B[1]

C[@]

F5 - Place/Unplace breakpoint in current line.

F4 - Enable/Disable function trace.

Keys can be easy changed in .vimrc configuration file.

 

How to install debugger?

1. Add next lines to your ~/.vimrc:  

Code )

Comment

:set number and augroup CursorLine block is not critical and can be moved if wish.

You must be owner of this file.

 

2. Create debugger.sh script in ~/.vim/ folder.

Code )


Set permition to execute it

chmod 755 debugger.sh

 

Debugger's code is not easy to read, because it must be created in 1 line. This line will be inserted in your script for debugging.
It is safe. It insert trap command which executes after each line in bash script. This trap show variables and control execution to next breakpoints.

Known issues

1. Breakpoints does not work on empty lines. Also breakpoints can not work on return, fi, then, else and other second part of composite bash operators. If need, you can use operator : . Command : (no operation) do nothing. This is DEBUG signal behaviour of command trap in bash.
2. It is not configured to debug 2 different scripts under 1 user. In this case will be executed and traced last loaded script.
3. Debugger use own variables, which starts from mydebug_. I think you will not use this prefix.))) If you use variable with similar name, but it is not declared, then your variable can be predefined with not empty value.
Debugger's command will be as second line of your script in trace mode. It always inserts after she-bang line.
Мітки:

Про мене

dikiy_mujchina: (Default)
dikiy_mujchina

December 2019

S M T W T F S
1234 567
891011121314
15161718192021
22232425262728
293031    

RSS

RSS Atom

Мітки

Резюме сторінки

За стиль дякую

Показати приховане

No cut tags
Page generated Sep. 25th, 2025 10:51 pm
Powered by Dreamwidth Studios