# -*- mode: shell-script -*-
# Copyright (C) 2022-2026 Free Software Foundation, Inc.
#
# This file is part of GNU Emacs.
#
# GNU Emacs is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
#
# Use 'lldb --local-lldbinit' or add to your ~/.lldbinit the line
#
# settings set target.load-cwd-lldbinit true
#
# Emacs-specific commands start with 'x'.  Type 'help' to see all
# commands.  Type 'help <command>' to see help for a command
# <command>.

# Make Python find our files
script -- sys.path.append('../etc')

# Load our Python files
command script import emacs_lldb

# Reload emacs_lldb.py
command alias xreload command script import emacs_lldb

# Print with children provider, depth 2.
command alias xprint frame variable -P 2

# MPS telemetry level (default output file mpsio.log)
#env MPS_TELEMETRY_CONTROL=all

# b xsignal
b pkg_break
#b pkg_error
#b Fpkg_read
b igc_break
b malloc_error_break
# When an assertion in MPS fails
b mps_lib_assert_fail

# Whlle dying, Emacs may allocate from MPS, although we're dying
# from having an assertion fail in code called from MPS. This leads
# to misleading situations, like pthread_mutex_lock reporting EDEADLK
# because we're owning the lock already, and so on.
b emacs_abort
b die

#watchpoint set expression --size 8 --watch write -- (char*) pkg->symbols

# To find out from where macOS prints stuff to stderr, like
# 023-07-20 13:41:17.073449+0200 emacs[53072:1205906] [default]
#    CGSWindowShmemCreateWithPort failed on port 0
# b libsystem_trace.dylib``_os_log_error_impl
# Print with children provider, depth 2.
#command alias xprint frame variable -P 2

#process handle -p true -s false SIGSEGV
#process handle -p true -s false SIGBUS

#target create temacs
#settings set -- target.run-args --batch  -l loadup --temacs=pbootstrap --bin-dest  --eln-dest
#command alias go process launch --working-dir .

#target create emacs
#env EMACS_TEST_DIRECTORY=/Users/gerd/emacs/github/igc/test
#command alias go process launch --working-dir ../test
#settings set -- target.run-args --module-assertions --no-init-file --no-site-file --no-site-lisp -L ":." -l ert --eval "(setq treesit-extra-load-path '(\"/Users/gerd/.emacs.d/tree-sitter\"))" -l lisp/emacs-lisp/package-tests --batch --eval '(ert-run-tests-batch-and-exit (quote (not (or (tag :expensive-test) (tag :unstable) (tag :nativecomp)))))'

# Von Helmut:
#target create emacs
#command alias go process launch --tty --working-dir .
#settings set -- target.run-args -Q --eval '(progn (view-hello-file) (redisplay) (igc--collect) (forward-line))'

#target create temacs
#settings set -- target.run-args --batch  -l loadup --temacs=pbootstrap --bin-dest not-set --eln-dest not-set
#command alias go process launch --working-dir .
##settings set target.disable-aslr false

#target create /Users/gerd/Desktop/igc.app/Contents/MacOS/Emacs
#command alias go process launch --working-dir /Users/gerd/emacs/savannah/igc/
#settings set target.disable-aslr false

# target create bootstrap-emacs
# settings set -- target.run-args -batch --no-site-file --no-site-lisp  -f batch-byte-compile emacs-lisp/macroexp.el
# command alias go process launch --working-dir ../lisp

target create bootstrap-emacs
settings set -- target.run-args -batch --no-site-file --no-site-lisp  -f batch-byte-compile emacs-lisp/bytecomp.el
command alias go process launch --disable-aslr false --working-dir ../lisp

# target create ./bootstrap-emacs
# settings set -- target.run-args --batch  -l loadup --temacs=pbootstrap --bin-dest /Users/gerd/emacs/github/igc-copy/nextstep/Emacs.app/Contents/MacOS/ --eln-dest /Users/gerd/emacs/github/igc-copy/nextstep/Emacs.app/Contents/Frameworks/
# settings set target.disable-aslr false
# command alias go process launch --working-dir .
#
#target create emacs
#settings set -- target.run-args -batch --no-site-file --no-site-lisp --eval "(setq load-prefer-newer t byte-compile-warnings 'all)" --eval "(setq org--inhibit-version-check t)"  -f batch-byte-compile leim/ja-dic/ja-dic.el
#settings set target.disable-aslr false
#command alias go process launch --working-dir ../lisp
#target create bootstrap-emacs
#settings set -- target.run-args -batch --no-site-file --no-site-lisp --eval "(setq load-prefer-newer t byte-compile-warnings 'all)" --eval "(setq org--inhibit-version-check t)"  -l comp -f byte-compile-refresh-preloaded -f batch-byte+native-compile ../lisp/isearch.el
#command alias go process launch --disable-aslr false --working-dir .
#b wrong_type_argument

#target create temacs
#settings set -- target.run-args --batch  -l loadup --temacs=pbootstrap --bin-dest /Users/gerd/emacs/github/igc-copy/nextstep/Emacs.app/Contents/MacOS/ --eln-dest /Users/gerd/emacs/github/igc-copy/nextstep/Emacs.app/Contents/Frameworks/
#command alias go process launch --working-dir .

target create emacs
settings set -- target.run-args
command alias go process launch --working-dir .
