Skip to content

Commit dc430db

Browse files
codeon-natmulle-nat
authored andcommitted
Call it __get_or_create_mulle_objc_runtime, just
because it's more telling. Add mulle_objc_lldb.c/h for debugger support. Moved some code from class into call, where its placed more sensibly. Be conservative with the reading of MULLE_OBJC_NEVER_RELEASE for now.
1 parent 549f75b commit dc430db

22 files changed

+548
-360
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ src/mulle_objc_try_catch_finally.h
7676
src/mulle_objc_uniqueid.h
7777
src/mulle_objc_walktypes.h
7878
src/mulle_objc_version.h
79+
src/debug/mulle_objc_lldb.h # kinda private
7980
${DEBUG_HEADERS}
8081
)
8182

@@ -106,6 +107,7 @@ src/mulle_objc_runtime.c
106107
src/mulle_objc_runtime_global.c
107108
src/mulle_objc_signature.c
108109
src/mulle_objc_uniqueid.c
110+
src/debug/mulle_objc_lldb.c # always add
109111
)
110112

111113

RELEASENOTES.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
## 0.7.1
22

3+
> This version has changes mostly to the benefit of the mulle-lldb debugger
4+
5+
* moved some more call functions into "call" (duh) added a shadow call to make
6+
the stacktrace easier for the debugger to step out of
37
* moved version and new "path" up for easier debugging and easier version
48
checks its kinda useful if version is at a fixed offset
9+
* `__get_or_create_objc_runtime` has been renamed to `__get_or_create_mulle_objc_runtime`
10+
for clarity in the debugger and multi runtime code.
11+
* moved forward into a fixed position in the class structure for a future
12+
debugger
13+
* the forward function is now fixed to be names as
14+
`__forward_mulle_objc_object_call` as a benefit to the debugger. Let's put it
15+
this way, you can still forward on a per class basis, but the debugger won't
16+
pick up on it. Which isn't a problem just not as gainly looking in the
17+
stacktrace'
518

619
## 0.6.1
720

dox/API_IVAR.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Get the name of this instance variable. This pointer is alive as long as
1717
`ivar` is alive and unmodified. Don't free it.
1818

1919

20-
### `mulle_objc_ivar_get_id`
20+
### `mulle_objc_ivar_get_ivarid`
2121

2222
```
23-
mulle_objc_ivarid_t mulle_objc_ivar_get_id( struct _mulle_objc_ivar *ivar)
23+
mulle_objc_ivarid_t mulle_objc_ivar_get_ivarid( struct _mulle_objc_ivar *ivar)
2424
```
2525

2626
Get the **ivarid** of this instance variable.

dox/API_RUNTIME.md

+8-36
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct _mulle_objc_classpair *mulle_objc_runtime_new_classpair(
5757
mulle_objc_classid_t classid,
5858
char *name,
5959
size_t instance_size,
60-
struct _mulle_objc_class *superclass);
60+
struct _mulle_objc_infraclass *superclass);
6161
```
6262

6363
Create a new `_mulle_objc_classpair`, the class pair is not yet added to the
@@ -75,11 +75,11 @@ Parametername | Description
7575
Returns NULL on error. Check `errno` for error codes.
7676

7777

78-
### `mulle_objc_runtime_add_class`
78+
### `mulle_objc_runtime_add_infraclass`
7979

8080
```
81-
int mulle_objc_runtime_add_class( struct _mulle_objc_runtime *runtime,
82-
struct _mulle_objc_class *cls);
81+
int mulle_objc_runtime_add_infraclass( struct _mulle_objc_runtime *runtime,
82+
struct _mulle_objc_infraclass *cls);
8383
```
8484

8585
Add a class `cls` to `runtime`. Returns 0 on success, otherwise check `errno`
@@ -106,58 +106,30 @@ cls = mulle_objc_classpair_get_infraclass( pair);
106106
mulle_objc_runtime_add_class( runtime, cls);
107107
```
108108

109-
### `mulle_objc_runtime_lookup_class`
109+
### `mulle_objc_runtime_get_or_lookup_infraclass`
110110

111111
```
112-
struct _mulle_objc_class *mulle_objc_runtime_lookup_class(
112+
struct _mulle_objc_class *mulle_objc_runtime_get_or_lookup_class(
113113
struct _mulle_objc_runtime *runtime,
114114
mulle_objc_classid_t classid)
115115
```
116116

117117
Retrieve class with `classid` from `runtime`. Returns NULL if not found.
118118

119119

120-
### `mulle_objc_runtime_add_gift`
121-
122-
```
123-
void mulle_objc_runtime_add_gift( struct _mulle_objc_runtime *runtime,
124-
void *gift)
125-
```
126-
127-
Give the runtime a memory block `gift` allocated with
128-
`mulle_objc_runtime_calloc` or `mulle_objc_runtime_malloc`. Gift will be
129-
deallocated on deallocation of the runtime.
130-
131-
The intention of gifts is to provide a reclaiming mechanism for classes,
132-
classnames, methodlist et.c. to avoid leaks.
133-
134-
135120
### `mulle_objc_runtime_calloc`
136121

137122
```
138123
void *mulle_objc_runtime_calloc( struct _mulle_objc_runtime *runtime, size_t n, size_t size)
139124
```
140125

141-
`calloc` some memory using the memory allocator of the runtime. Use this for
142-
creating "gifts" (-> `mulle_objc_runtime_add_gift`)
143-
126+
`calloc` some memory using the memory allocator of the runtime. This automatically gifts the memory to the runtime!
144127

145128
### `mulle_objc_runtime_realloc`
146129

147130
```
148131
void *mulle_objc_runtime_realloc( struct _mulle_objc_runtime *runtime, void *block, size_t size)
149132
```
150133

151-
`realloc` some memory using the memory allocator of the runtime. Use this for
152-
creating "gifts" (-> `mulle_objc_runtime_add_gift`)
153-
134+
`realloc` some memory using the memory allocator of the runtime.This automatically gifts the memory to the runtime!
154135

155-
### `mulle_objc_runtime_free`
156-
157-
```
158-
void mulle_objc_runtime_free( struct _mulle_objc_runtime *runtime, void *block)
159-
```
160-
161-
Free memory that was created by `mulle_objc_runtime_calloc` or
162-
`mulle_objc_runtime_realloc`. Don't free memory you have "gifted" to the
163-
runtime.

mulle-objc-runtime.xcodeproj/project.pbxproj

+16-10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
4138D0E31CC6704B00940B7B /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 4138D0E21CC6704B00940B7B /* main.c */; };
5252
4138D0F01CC6716A00940B7B /* mulle_objc_fnv1.c in Sources */ = {isa = PBXBuildFile; fileRef = 41E8B0591CC6324700D1F169 /* mulle_objc_fnv1.c */; };
5353
4138D0F11CC6727B00940B7B /* mulle_objc_uniqueid.c in Sources */ = {isa = PBXBuildFile; fileRef = 41A2882E1C65597A00BBA54E /* mulle_objc_uniqueid.c */; };
54+
413BB5F21ECE005900106271 /* mulle_objc_lldb.c in Sources */ = {isa = PBXBuildFile; fileRef = 413BB5F01ECE005900106271 /* mulle_objc_lldb.c */; };
5455
4145BDFD1BDCDFED00C42630 /* mulle_objc_dotdump.c in Sources */ = {isa = PBXBuildFile; fileRef = 4145BDFB1BDCDFED00C42630 /* mulle_objc_dotdump.c */; };
5556
4145BDFE1BDCDFED00C42630 /* mulle_objc_dotdump.h in Headers */ = {isa = PBXBuildFile; fileRef = 4145BDFC1BDCDFED00C42630 /* mulle_objc_dotdump.h */; settings = {ATTRIBUTES = (Public, ); }; };
5657
4147BDC91A1CA4E100AE8831 /* mulle_objc_load.c in Sources */ = {isa = PBXBuildFile; fileRef = 4147BDC81A1CA4E100AE8831 /* mulle_objc_load.c */; };
@@ -167,6 +168,8 @@
167168
4137D8401C724E6C00102D35 /* mulle_objc_fastenumeration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mulle_objc_fastenumeration.h; sourceTree = "<group>"; };
168169
4138D0E01CC6704B00940B7B /* mulle-objc-uniqueid */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "mulle-objc-uniqueid"; sourceTree = BUILT_PRODUCTS_DIR; };
169170
4138D0E21CC6704B00940B7B /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
171+
413BB5F01ECE005900106271 /* mulle_objc_lldb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mulle_objc_lldb.c; sourceTree = "<group>"; };
172+
413BB5F41ECE38FE00106271 /* mulle_objc_lldb.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mulle_objc_lldb.h; sourceTree = "<group>"; };
170173
4145BDFB1BDCDFED00C42630 /* mulle_objc_dotdump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mulle_objc_dotdump.c; sourceTree = "<group>"; };
171174
4145BDFC1BDCDFED00C42630 /* mulle_objc_dotdump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mulle_objc_dotdump.h; sourceTree = "<group>"; };
172175
4147BDC81A1CA4E100AE8831 /* mulle_objc_load.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mulle_objc_load.c; sourceTree = "<group>"; };
@@ -318,17 +321,17 @@
318321
41978C351A1DF8C300DAFA51 /* mulle_objc_callqueue.h */,
319322
41978C331A1DF39600DAFA51 /* mulle_objc_callqueue.c */,
320323
416BA7791A19028F002F603A /* mulle_objc_class.h */,
321-
41212A211E97DAAA0089F711 /* mulle_objc_class_struct.h */,
322324
416BA77A1A1902AE002F603A /* mulle_objc_class.c */,
325+
41212A211E97DAAA0089F711 /* mulle_objc_class_struct.h */,
326+
4177A9661D325C93007DC3D8 /* mulle_objc_class_convenience.h */,
327+
4177A9691D325DA6007DC3D8 /* mulle_objc_class_runtime.h */,
328+
4177A9681D325DA6007DC3D8 /* mulle_objc_class_runtime.c */,
329+
41212A0E1E97BE3A0089F711 /* mulle_objc_classpair.h */,
330+
41212A0D1E97BE3A0089F711 /* mulle_objc_classpair.c */,
323331
41212A121E97BF3C0089F711 /* mulle_objc_infraclass.h */,
324332
41212A111E97BF3C0089F711 /* mulle_objc_infraclass.c */,
325333
41212A161E97BF4B0089F711 /* mulle_objc_metaclass.h */,
326334
41212A151E97BF4B0089F711 /* mulle_objc_metaclass.c */,
327-
41212A0E1E97BE3A0089F711 /* mulle_objc_classpair.h */,
328-
41212A0D1E97BE3A0089F711 /* mulle_objc_classpair.c */,
329-
4177A9661D325C93007DC3D8 /* mulle_objc_class_convenience.h */,
330-
4177A9691D325DA6007DC3D8 /* mulle_objc_class_runtime.h */,
331-
4177A9681D325DA6007DC3D8 /* mulle_objc_class_runtime.c */,
332335
412002941C5FA7DF00ADFFE9 /* mulle_objc_fastclasstable.h */,
333336
4137D8401C724E6C00102D35 /* mulle_objc_fastenumeration.h */,
334337
4137D83F1C724E6C00102D35 /* mulle_objc_fastenumeration.c */,
@@ -377,14 +380,16 @@
377380
isa = PBXGroup;
378381
children = (
379382
41A963BD1CE2373800412367 /* c_set.inc */,
380-
41A963C01CE2384600412367 /* mulle_objc_html.h */,
381-
41A963BF1CE237AF00412367 /* mulle_objc_html.c */,
383+
418AAD401ECB193300A2DB18 /* mulle_objc_csvdump.h */,
384+
418AAD3F1ECB193300A2DB18 /* mulle_objc_csvdump.c */,
382385
4145BDFC1BDCDFED00C42630 /* mulle_objc_dotdump.h */,
383386
4145BDFB1BDCDFED00C42630 /* mulle_objc_dotdump.c */,
387+
41A963C01CE2384600412367 /* mulle_objc_html.h */,
388+
41A963BF1CE237AF00412367 /* mulle_objc_html.c */,
384389
41A963BA1CE2368E00412367 /* mulle_objc_htmldump.h */,
385390
41A963B91CE2368E00412367 /* mulle_objc_htmldump.c */,
386-
418AAD401ECB193300A2DB18 /* mulle_objc_csvdump.h */,
387-
418AAD3F1ECB193300A2DB18 /* mulle_objc_csvdump.c */,
391+
413BB5F41ECE38FE00106271 /* mulle_objc_lldb.h */,
392+
413BB5F01ECE005900106271 /* mulle_objc_lldb.c */,
388393
);
389394
path = debug;
390395
sourceTree = "<group>";
@@ -624,6 +629,7 @@
624629
418AAD411ECB193300A2DB18 /* mulle_objc_csvdump.c in Sources */,
625630
4154F1651AA20D9B004B7259 /* mulle_objc_signature.c in Sources */,
626631
416688C41C53E285005F4E3E /* mulle_objc_propertylist.c in Sources */,
632+
413BB5F21ECE005900106271 /* mulle_objc_lldb.c in Sources */,
627633
4111AFDA1D8049C100DFB901 /* mulle_objc_runtime_global.c in Sources */,
628634
4137D8411C724E6C00102D35 /* mulle_objc_fastenumeration.c in Sources */,
629635
);

src/debug/mulle_objc_lldb.c

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//
2+
// mulle_objc_lldb.c
3+
// mulle-objc-runtime
4+
//
5+
// Created by Nat! on 18.05.17.
6+
// Copyright © 2017 Mulle kybernetiK.
7+
// Copyright © 2017 Codeon GmbH.
8+
// All rights reserved.
9+
//
10+
// Redistribution and use in source and binary forms, with or without
11+
// modification, are permitted provided that the following conditions are met:
12+
//
13+
// Redistributions of source code must retain the above copyright notice, this
14+
// list of conditions and the following disclaimer.
15+
//
16+
// Redistributions in binary form must reproduce the above copyright notice,
17+
// this list of conditions and the following disclaimer in the documentation
18+
// and/or other materials provided with the distribution.
19+
//
20+
// Neither the name of Mulle kybernetiK nor the names of its contributors
21+
// may be used to endorse or promote products derived from this software
22+
// without specific prior written permission.
23+
//
24+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
// POSSIBILITY OF SUCH DAMAGE.
35+
//
36+
#include "mulle_objc_lldb.h"
37+
38+
#include "mulle_objc_call.h"
39+
#include "mulle_objc_class.h"
40+
#include "mulle_objc_infraclass.h"
41+
#include "mulle_objc_metaclass.h"
42+
#include "mulle_objc_method.h"
43+
#include "mulle_objc_runtime.h"
44+
45+
46+
# pragma mark - lldb support
47+
48+
mulle_objc_methodimplementation_t
49+
mulle_objc_lldb_lookup_methodimplementation( void *obj,
50+
mulle_objc_methodid_t methodid,
51+
void *cls_or_classid,
52+
int is_classid,
53+
int is_meta,
54+
int debug)
55+
{
56+
struct _mulle_objc_class *cls;
57+
struct _mulle_objc_metaclass *meta;
58+
struct _mulle_objc_runtime *runtime;
59+
struct _mulle_objc_infraclass *found;
60+
struct _mulle_objc_class *call_cls;
61+
mulle_objc_methodimplementation_t imp;
62+
63+
if( debug)
64+
fprintf( stderr, "lookup %p %08x %p (%d)\n", obj, methodid, cls_or_classid, is_classid);
65+
66+
if( ! obj || methodid == MULLE_OBJC_NO_METHODID || methodid == MULLE_OBJC_INVALID_METHODID)
67+
return( 0);
68+
69+
// ensure class init
70+
cls = is_meta ? obj : _mulle_objc_object_get_isa( obj);
71+
meta = _mulle_objc_class_is_metaclass( cls)
72+
? (struct _mulle_objc_metaclass *) cls
73+
: _mulle_objc_class_get_metaclass( cls);
74+
75+
// call "-class" so class initializes.. But WHY ??
76+
// if( ! _mulle_objc_metaclass_get_state_bit( meta, MULLE_OBJC_META_INITIALIZE_DONE))
77+
// mulle_objc_object_call( cls, MULLE_OBJC_CLASS_METHODID, NULL);
78+
79+
if( is_classid)
80+
{
81+
runtime = _mulle_objc_class_get_runtime( cls);
82+
found = _mulle_objc_runtime_unfailing_get_or_lookup_infraclass( runtime,
83+
(mulle_objc_classid_t) (uintptr_t) cls_or_classid);
84+
if( is_meta)
85+
call_cls = _mulle_objc_metaclass_as_class( _mulle_objc_infraclass_get_metaclass( found));
86+
else
87+
call_cls = _mulle_objc_infraclass_as_class( found);
88+
}
89+
else
90+
call_cls = cls_or_classid;
91+
92+
imp = _mulle_objc_class_lookup_or_search_methodimplementation_no_forward( call_cls, methodid);
93+
if( debug)
94+
{
95+
char buf[ s_mulle_objc_sprintf_functionpointer_buffer];
96+
97+
mulle_objc_sprintf_functionpointer( buf, (mulle_functionpointer_t) imp);
98+
fprintf( stderr, "resolved to %p -> %s\n", call_cls, buf);
99+
}
100+
return( imp);
101+
}
102+
103+
104+
struct _mulle_objc_methoddescriptor *
105+
mulle_objc_lldb_lookup_methoddescriptor_by_name( char *name)
106+
{
107+
mulle_objc_methodid_t methodid;
108+
struct _mulle_objc_runtime *runtime;
109+
110+
methodid = mulle_objc_uniqueid_from_string( name);
111+
runtime = mulle_objc_get_runtime();
112+
return( _mulle_objc_runtime_lookup_methoddescriptor( runtime, methodid));
113+
}
114+
115+
116+
// this is supposed to crash!
117+
void mulle_objc_lldb_check_object( void *obj, mulle_objc_methodid_t sel)
118+
{
119+
struct _mulle_objc_class *cls;
120+
121+
if( ! obj)
122+
return;
123+
124+
cls = _mulle_objc_object_get_isa( obj);
125+
strlen( cls->name); // try to crash here
126+
127+
if( ! _mulle_objc_class_lookup_methodimplementation_no_forward( cls, sel))
128+
*((volatile int *)0) = '1848'; // force crash
129+
}
130+
131+
132+
void *mulle_objc_lldb_get_dangerous_classstorage_pointer( void)
133+
{
134+
struct _mulle_objc_runtime *runtime;
135+
struct mulle_concurrent_hashmap *map;
136+
137+
runtime = mulle_objc_get_runtime();
138+
map = &runtime->classtable;
139+
return( _mulle_atomic_pointer_read( &map->next_storage.pointer));
140+
}
141+

0 commit comments

Comments
 (0)