* Refactor TLS module
- Replace unreliable `__errno_location()` trick with `pthread_self()` to acquire TLS address
- Consolidate heap heuristics checks about TLS within the `pwndbg.gdblib.tls` module for better organization
* Bug fix for the `errno` command
Calling `__errno_location()` without locking the scheduler can cause another thread to inadvertently continue execution
* Refactor code about heap heuristics of thread-local variables
- Replace some checks with some functions in `pwndbg.gdblib.tls`
- Try to find tcache with `mp_.sbrk_base + 0x10` if the target is single-threaded
* Add tests for heap heuristics with multi-threaded
* Refacotr scheduler-locking related functions
- Move these functions into `pwndbg.gdblib.scheduler`
- Fetch the parameter value once (https://github.com/pwndbg/pwndbg/pull/1536#discussion_r1082549746)
* Avoid bug caused by GLIBC_TUNABLES
See https://github.com/pwndbg/pwndbg/pull/1536#discussion_r1083202815
* Add note about `set scheduler-locking on`
* Add comment for `lock_scheduler`
Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
* Update DEVELOPING.md
Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
This fixes memoize when debug=True is set in pwndbg/lib/memoize.py
Before this commit, one gets the following error:
```
dc@jhtc:~$ gdb
Executed: <stop-memoized function pwndbg.ida.available>(())
.... False
Traceback (most recent call last):
File "/home/dc/pwndbg/gdbinit.py", line 100, in <module>
import pwndbg # noqa: F401
File "/home/dc/pwndbg/pwndbg/__init__.py", line 11, in <module>
load_commands()
File "/home/dc/pwndbg/pwndbg/commands/__init__.py", line 601, in load_commands
import pwndbg.commands.cymbol
File "/home/dc/pwndbg/pwndbg/commands/cymbol.py", line 53, in <module>
pwndbg_cachedir = pwndbg.lib.tempfile.cachedir("custom-symbols")
File "/home/dc/pwndbg/pwndbg/lib/memoize.py", line 52, in __call__
print("%s: %s(%r)" % (how, self, args))
File "/home/dc/pwndbg/pwndbg/lib/memoize.py", line 58, in __repr__
return "<%s-memoized function %s>" % (self.kind, funcname)
AttributeError: 'forever' object has no attribute 'kind'
/home/dc/.gdbinit:12: Error in sourced command file:
No symbol table is loaded. Use the "file" command.
```
* Fix#855: Rust binaries debugging
This fixes#855 by using a workaround when we set language to C, fetch
symbols and set language back to Rust or auto.
Note that I also extended the list of symbols we fetched as... it seems
that the C language that is being set during some events may not have
e.g. `short` but may have a `short int` symbol. This is kinda weird, but
this is how it is. Idk if that's a GDB bug or what.
```
ipdb> gdb.execute('show language')
The current source language is "auto; currently c".
ipdb> gdb.lookup_type('short')
*** gdb.error: No type named short.
ipdb> gdb.lookup_type('int')
<gdb.Type object at 0x7fd35b550dc8>
ipdb> gdb.lookup_type('short int')
<gdb.Type object at 0x7fd35b550e68>
ipdb> gdb.lookup_type('long int')
<gdb.Type object at 0x7fd35b550e18>
```
* fix code review issues