patch 9.1.0878: termdebug: cannot enable DEBUG mode

Problem:  termdebug: cannot enable DEBUG mode
Solution: Allow to specify DEBUG mode (Ubaldo Tiberi)

closes: #16080

Signed-off-by: Ubaldo Tiberi <ubaldo.tiberi@volvo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/doc/tags b/runtime/doc/tags
index 706970f..39f279d 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -10688,6 +10688,7 @@
 termdebug-stepping	terminal.txt	/*termdebug-stepping*
 termdebug-timeout	terminal.txt	/*termdebug-timeout*
 termdebug-variables	terminal.txt	/*termdebug-variables*
+termdebug_contributing	terminal.txt	/*termdebug_contributing*
 termdebug_disasm_window	terminal.txt	/*termdebug_disasm_window*
 termdebug_evaluate_in_popup	terminal.txt	/*termdebug_evaluate_in_popup*
 termdebug_map_K	terminal.txt	/*termdebug_map_K*
diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt
index 637277a..593dec7 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -1,4 +1,4 @@
-*terminal.txt*	For Vim version 9.1.  Last change: 2024 Nov 10
+*terminal.txt*	For Vim version 9.1.  Last change: 2024 Nov 19
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -1737,4 +1737,23 @@
 	  let g:termdebug_config['evaluate_in_popup'] = v:false
 	endfunc
 <
+
+Contributing ~
+						*termdebug_contributing*
+Contributions for termdebug improvements are welcome.
+However, it is fairly common that during the development process you need some
+mechanisms like `echo` statements (or similar) to help you in your job.
+For this reason, you can set: >
+    let g:termdebug_config['debug'] = true
+<
+This sets the `DEBUG` variable to `true` in the source code that you can use
+within the source code. An example of its usage follows: >
+    if exists('g:termdebug_loaded')
+      if DEBUG
+	Echoerr('Termdebug already loaded.')
+      endif
+      finish
+    endif
+<
+
  vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
index 6f1f4b5..9fbf3b7 100644
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -4,7 +4,7 @@
 
 # Author: Bram Moolenaar
 # Copyright: Vim license applies, see ":help license"
-# Last Change: 2024 Jul 04
+# Last Change: 2024 Nov 19
 # Converted to Vim9: Ubaldo Tiberi <ubaldo.tiberi@gmail.com>
 
 # WORK IN PROGRESS - The basics works stable, more to come
@@ -38,6 +38,11 @@
 # The communication with gdb uses GDB/MI.  See:
 # https://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html
 
+var DEBUG = false
+if exists('g:termdebug_config')
+  DEBUG = get(g:termdebug_config, 'debug', false)
+endif
+
 def Echoerr(msg: string)
   echohl ErrorMsg | echom $'[termdebug] {msg}' | echohl None
 enddef
@@ -49,7 +54,9 @@
 # Variables to keep their status among multiple instances of Termdebug
 # Avoid to source the script twice.
 if exists('g:termdebug_loaded')
-  Echoerr('Termdebug already loaded.')
+  if DEBUG
+    Echoerr('Termdebug already loaded.')
+  endif
   finish
 endif
 g:termdebug_loaded = true