https://lldb.llvm.org/use/tutorial.html

Pfff... Under Macos ARM, for unknown reasons, a breakpoint set in xcode can't be activated.
The workaround I use is to declare the breakpoint in the lldb window.
For that, I must use a pull instruction, then pause the execution, then declare the breakpoint,
then contnue execution.

arguments: -e "pull; say SysLoadFuncs()"
breakpoint set --file rexxutil.cpp --line 1125


===========================================================================================
https://news.ycombinator.com/item?id=35092998
What a good debugger can do

    This comment about logging messages:
    https://news.ycombinator.com/item?id=35104951


==========================================================================================

Debug SysFileTree

dans gdb :
info b --> trouver le n° du breakpoint (ici 13)
ignore 13 19539 --> nbre de PROCHAINS passages à ignorer

Note : pour savoir combien de passages ignorer, mettre le breakpoint
et cocher "automatically continue"

RexxNativeActivation::variablePoolInterface(PSHVBLOCK pshvblock)
    RexxNativeActivation::variablePoolRequest(PSHVBLOCK pshvblock)
        RXSHV_SYSET : RexxNativeActivation::variablePoolSetVariable(PSHVBLOCK pshvblock)

p ldp->truefile
affichage tronqué.
Pour voir la totalité :
set print elements 0

"/Users/jlfaucher/Library/Caches/Metadata/Safari/History/http:%2F%2Fdeveloper.apple.com%2Flibrary%2Fmac%2F%23documentation%2FDeveloperTools%2FReference%2FXcodeBuildSettingRef%2F1-Build_Setting_Reference%2Fbuild_setting_ref.html%23%2F%2Fapple_ref%2Fdoc%2Fuid%"


==========================================================================================

OutputDebugString
http://www.unixwiz.net/techtips/outputdebugstring.html

syslog
http://fr.wikipedia.org/wiki/Syslog
http://www.linux-kheops.com/doc/man/manfr/man-html-0.9/man3/syslog.3.html
LOG_USER | LOG_DEBUG


==========================================================================================

http://www.oklabs.net/skype-reverse-engineering-the-long-journey/
Montre comment utiliser Olly dbg


===============================================================================
jlf Apr 14, 2021
In dbgprintf, I replaced syslog (Linux & MacOs) and OutputDebugString (Windows)
by printf
because I was not able to retrieve the debug text under MacOs.
The procedure described below did not work for me in 2021...


(copied from _diary.txt)
2010 may 15

Added the function dbgprintf to write debug strings.
Under Windows, it calls OutputDebugString.
Under Linux, it calls syslog.

Remember, typical debug session under PuppyLinux (with busybox) :
Open a console :
    syslogd -S -C   # -S Smaller loggin output. -C Log to share mem buffer (read it using logred).
    logread -f
    The output of syslog is displayed by logread in this console (lock management, on client and server side).
Open a console, launch rxapi.
    Has been compiled to stay as a foreground process.
    It sends debug strings to stderr, more easy to follow in this console (messages between client and server).
Open a console, run the rexx command. The two other consoles are updated with debug infos.


[2011 apr 25 update]
Under MacOsX, I see this message in console : process exceeded 500 log messages per second limit.
To bypass this limit :
Edit /System/Library/LaunchDaemons/com.apple.syslogd.plist with xcode (binary format)
Search for : <string>/usr/sbin/syslogd</string>
Add these lines to the program arguments section :
<string>-mps_limit</string>
<string>0</string>
A value of 0 disables the limit. The default is 500 messages per second.
Restart the syslog daemon with:
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
-----
LOG_DEBUG messages still not visible in console...
Probably because of /etc/asl.conf :
    # save everything from emergency to notice
    ? [<= Level notice] store
Remember :
    Emergency     (level 0)
    Alert         (level 1)
    Critical      (level 2)
    Error         (level 3)
    Warning       (level 4)
    Notice        (level 5)
    Info          (level 6)
    Debug         (level 7)
-----
Create the file /var/log/debug.log :
sudo touch /var/log/debug.log
Add this line to /etc/syslog.conf to get the debug messages in /var/log/debug.log :
*.debug   /var/log/debug.log
then restart the syslogd daemon as explained above.

================================================================================
14/07/2021 (copied from ~/Dropbox/software/oorexx/doc/ooRexx.txt
================================================================================

data breakpoint:
memory breakpoint:

lldb) p this->named_argumentCount
(uint16_t) $1 = 1
(lldb) p &(this->named_argumentCount)
(uint16_t *) $2 = 0x000000010241ce74
(lldb) p sizeof(this->named_argumentCount)
(unsigned long) $3 = 2
(lldb) w s e -s 2 -- 0x000000010241ce74
Watchpoint created: Watchpoint 1: addr = 0x10241ce74 size = 2 state = enabled type = w
    new value: 14275852816613377


print variable:
p RexxBehaviour::primitiveBehaviours[0]


(lldb) p &(this->waitingActivities)
(ArrayClass **) 0x000000012c007c50

(lldb) p sizeof(this->waitingActivities)
(unsigned long) 8

p &(waitingActivities->behaviour)

waitingActivities	ArrayClass *	0x138651360	0x0000000138651360
(lldb) w s e -s 8 -- 0x0000000138651378
waitingActivities	ArrayClass *	0x138575370	0x0000000138575370
(lldb) w s e -s 8 -- 0x0000000138575388
waitingActivities	ArrayClass *	0x1410265d0	0x00000001410265d0
(lldb) w s e -s 8 -- 0x00000001410265e8


================================================================================
debug a RexxString field overwritten
================================================================================

The crash happen when evaluating the string literal 'DATETIME' in StreamClasses.orx

::METHOD query                         /* standard query routine            */
  use strict arg subcommand
  parse upper var subcommand subcommand parms
  signal on notready
  subcommand = ' 'subcommand           /* add a leading blank               */
                                       /* resolve abbreviations             */
  parse value ' DATETIME EXISTS HANDLE POSITION SEEK SIZE STREAMTYPE TIMESTAMP' with (subcommand) +1 subcommand .
  select
                                       /* need the date and time?           */
    when subcommand = 'DATETIME' then do


printf("RexxString::evaluate this=%x value=%x encoding=%x for %s\n", this, value, this->encoding, this->getStringData());
output
RexxString::evaluate this=10295220 value=d228 encoding=d228 for DATETIME

where value = this->text (not displayed by the printf)
why do I have d228 in this->text and this->encoding?
both fields should be equal to this or to OREF_NULL

RexxString
8   HashCode hashValue;                 // stored has value
8   size_t length;                      /* string length in bytes          */
8   RexxObject *text;                   // The text counterpart or OREF_NULL
8   RexxObject *encoding;               // Placeholder, not yet the real encoding.
8   RexxNumberString *NumberString;     /* lookaside information           */
8   size_t Attributes;                  /* string attributes               */
4   char stringData[4];                 /* Start of the string data part   */
---
52 --> 56 to be aligned?

p sizeof(RexxString)
96

p sizeof(RexxObject)
40

Testing the addresses on a RexxString *variable
0x00000001180600d0	this
0x0000000118060108	this.text		+56     0x118060108 + 56 =      (118060108~x2d + 56)~d2x= -- 118060140
0x0000000118060110	this.encoding	+8

numeric digits 17
say 118060108~x2d - 1180600d0~x2d	-- 56 (40 + 8 + 8)
say 118060110~x2d - 118060108~x2d	-- 8

LLDB watchpoint (8 bytes to watch at address 0x118060140)
w s e -s 8 -- 0x118060140

Remember
only 1, 2, 4 or 8 is allowed for size

8315220
(8315220~x2d + 56)~d2x=     -- 8315258
w s e -s 8 -- 0x8315258


--------------------------------------------------------------------------------
Exception when debugging oodialog.wchar
I see several ASM instructions that are new to me...
cpuid
xgetbv
vmovd       xmm0,ecx
vpshufd     xmm0,xmm0,0
vinsertf128 ymm0,ymm0,xmm0,1
vmovdqu     ymm7,ymm0
vmovdqu     ymm8,ymm0
vmovdqu     ymm15,ymm0


--------------------------------------------------------------------------------
debug crash stack overflow

RexxActivity.cpp
put breakpoint in
RexxActivity::raisePropagate
on line
    activation->trap(condition, conditionObj);
with hit count 1000000

See at which count the crash occurs
and then analyze precisely at this count.


Exemple of code to force the crash :
{say arg(1); .context~executable~(1+arg(1))}~(0)


--------------------------------------------------------------------------------
Remember (debug stack overflow)

RexxActivity.cpp
RexxActivity::checkStackSpace

replace #if 0 by #if 1
to activate the debug output


This file has been adapted to debug a stack overflow :
Dropbox\software\do\do_rexx\stack_overflow


--------------------------------------------------------------------------------
To debug rexximage

With ooRexx 4.2:
    cdbuild
    cp .libs/*.dylib ../delivery/lib/

    because it's the libraries under delivery that are used.
    If you want to see that by yourself :
    otool -L .libs/rexximage

    cd .libs
    cp $builder_src_dir/interpreter/RexxClasses/*.orx .
    cp $builder_src_dir/interpreter/platform/unix/*.orx .


With ooRexx 5 and Executor:
    nothing to copy, ready to debug in place.


--------------------------------------------------------------------------------

/local/rexx/oorexx/build/executor.master/sandbox/jlf/trunk/macos/clang/debug/64/build/.libs$ lldb ./rexximage
(lldb) target create "./rexximage"
Current executable set to './rexximage' (x86_64).
(lldb) run
Process 9291 launched: './rexximage' (x86_64)
Process 9291 stopped
* thread #1: tid = 0xe38e7, 0x000000010000b818 librexx.4.dylib`rxStringSize<unsigned long, 1>::rxStringSize(this=0x00007fff5f400038, t=128043) + 24 at rexx.h:273, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7fff5f3ffff8)
    frame #0: 0x000000010000b818 librexx.4.dylib`rxStringSize<unsigned long, 1>::rxStringSize(this=0x00007fff5f400038, t=128043) + 24 at rexx.h:273
   270 	    static rxStringSize value(T s) { return rxStringSize<T, D>(s); }
   271 	public:
   272 	    rxStringSize() /* : size(0) */ {} // Must NOT assign 0 because some constructors are sometimes called directly, and this assignement overrides some values already assigned... Strange practice, but...
-> 273 	    rxStringSize(T t) : size(t) {}
   274 	    rxStringSize(int t) : size(t) {}
   275 	    rxStringSize(const rxStringSize<T, D> &s) : size(s.size) {}
   276 	    T value() const { return size; }
(lldb) bt

