Using app with Instruments on M1

What is the magic ingredient to get Instruments working with my app on an M1? I only get an error “Failed to gain authorization”:

  • debugger (ad hoc or full codesign) or built app (codesigned AND notarised).
  • Intel or ARM

What is a debugging entitlement?

Here are my entitlements:

You need “com.apple.security.get-task-allow” entitlement to get debugged.

@Christian Schmitz: Cough - I have to connect/disconnect every time I write to SQLite or I get crashes. Each connection seems to leak:

Does the MBS plugin have a non-leaking trim?

Thank you for the notice on the AddTraceListener. We’ll fix that.

For the trim function, well, the trim function creates a string, but it may not be freed somewhere else.

The Trim is part of the code that munges email headers. So if it’s not Trim that is leaking then the whole class would be problematic. I’ll try replacing the Trim with a Regex first.

Um… I wanted to make a very simple test for Trim. But I don’t even come that far:

dim s as string = " blabla "

for i as Integer = 0 to 10000
  s = s + s
next

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_platform.dylib 0x000000018665efa4 _platform_strlen + 4
1 XojoFramework 0x0000000104e4a098 StringOpsClassic::ConstructFromBuffer(char const*, unsigned int, int) + 40
2 XojoFramework 0x0000000104e5aa30 string::ConstructFromBuffer(char const*, unsigned long, unsigned int) + 92
3 XojoFramework 0x0000000104e5b7c0 operator+(string const&, string const&) + 120
4 XojoFramework 0x0000000104f90c44 RuntimeAddString + 112

I think the string you are creating is too large.
A loop from 0 to 26 uses up 1GB of RAM so imagine what 0 to 10000 does.

1 Like

Yes, the string is too large. However, this is in 64 bit so I should be able to shoot myself in the foot.

I estimate that a loop of 0 to 59 would require: 8,589,934,592 GB (8,388,608 TB)

Why is it the String that is too large?
I suspect it’s more the fact that a lot of Strings are being instantiated in that loop.
And memory management might kick in too late (*).

This works just fine in a 32Bit app:

Dim s As String = " blabla "

Dim sa() As String
For i As Integer = 0 To 10000
  sa.Append(s)
Next

s = Join(sa, "")

(*) I’d actually like to read an explanation about what’s really happening with the other code. Why that leads to a crash which I suspect is an “Out of Memory” situation.

Beatrix’s loop would cause the string length to exceed the size of a UInt64 very quickly because it is doubling the size of the string on each iteration.

The reason your code works is that it is creating 10,000 strings which is not the same as what Beatrix’s code does.

Yeah, I was just doing something stupid.

1 Like

:man_facepalming:
That’s what I get for just briefly looking at it without thinking much…

Right… and it just reminded me of :newspaper_roll: Paper and Moon :full_moon: