Is the number before selector name in crash log meaningful to developer? - objective-c

Sometimes, we can see some log trace with line number as 0 as the following:
Thread 21 Crashed:
0 libobjc.A.dylib 0x00000001a04cf28c objc_release + 16
1 MyApp 0x000000010252eec0 __30-[MyAPIClient invoke:]_block_invoke.115 (MyAPIClient.m:0)
2 MyApp 0x00000001023876fc __63-[MyTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke (MyTask.m:0)
3 ...
That's because related code is in block.
But for the numbers __30 and __63 above, are the numbers before the selector name meaningful? Or are they just numbers assigned to related blocks during compilation?

Related

How to convert Stack based instructions to Register based

This is what I have tested with the dis module in python -
>>> def f():
... a = 1
... b = 2
... c = 3
... a = b + c * a
... return a + c
...
>>> dis.dis(f)
2 0 LOAD_CONST 1 (1)
2 STORE_FAST 0 (a)
3 4 LOAD_CONST 2 (2)
6 STORE_FAST 1 (b)
4 8 LOAD_CONST 3 (3)
10 STORE_FAST 2 (c)
5 12 LOAD_FAST 1 (b)
14 LOAD_FAST 2 (c)
16 LOAD_FAST 0 (a)
18 BINARY_MULTIPLY
20 BINARY_ADD
22 STORE_FAST 0 (a)
6 24 LOAD_FAST 0 (a)
26 LOAD_FAST 2 (c)
28 BINARY_ADD
30 RETURN_VALUE
Those are instructions for a stack-based virtual machine. Is there any way to convert the above stack-based instructions into register-based instructions provided I have access to unlimited number of registers.
I only know about one tool which does that, we know that JVM is stack based but Dalvik VM is register-based. When we write code in Java, the class files contain stack based instructions and the dx tool converts the stack based instructions to register based instructions so that it can run in the Dalvik VM. So most probably there could be an algorithm somewhere which I have missed.
Also can there be an edge can where the stack could dynamically grow and shrink(which would be decided in runtime) , in that case it would be impossible to convert stack based instructions to register based. However one tool does it.
Can someone point me to the correct direction. Or know any algorithm which can help in this.

Runtime Exception when cordova app is run on xcode

I have created a cordova project and added ios platform , am using cordova-plugin-firebase-database from chemerisuk to have javascript based platfrom to connect to firebase-database, the build for xcode succeeds however when run on emulator it causes the exception .
cordova-plugin-firebase is the base plugin for corodova-plugin-firebase-database, however as there are no firbase database related services in this plugin hence am using cordova-plugin-firebase-database.
i am using GoogleService-Info.plist s, and i have Linked the object linker after referring to the firebase website ->$(OTHER_LDFLAGS) -ObjC in to the xcode.
I have cleaned the workspace and deleted the build files which was suspected to be the cause for this error , but even then it didnt workout.
I am getting the below error.
2019-02-07 16:58:16.810031+0900 HelloCordova[11898:1643374] +[FIRApp registerAsConfigurable:]: unrecognized selector sent to class 0x1080dfdc0
2019-02-07 16:58:16.812181+0900 HelloCordova[11898:1643374] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FIRApp registerAsConfigurable:]: unrecognized selector sent to class 0x1080dfdc0'
* First throw call stack:
(
0 CoreFoundation 0x0000000109dea1bb exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000108bcc735 objc_exception_throw + 48
2 CoreFoundation 0x0000000109e08e44 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000109deeed6 ___forwarding_ + 1446
4 CoreFoundation 0x0000000109df0da8 _CF_forwarding_prep_0 + 120
5 libobjc.A.dylib 0x0000000108bcdf85 call_load_methods + 705
6 libobjc.A.dylib 0x0000000108bcec04 load_images + 77
7 ??? 0x00000001082ba068 0x0 + 4432044136
8 ??? 0x00000001082c77a2 0x0 + 4432099234
9 ??? 0x00000001082c6974 0x0 + 4432095604
10 ??? 0x00000001082c6a08 0x0 + 4432095752
11 ??? 0x00000001082ba388 0x0 + 4432044936
12 ??? 0x00000001082be497 0x0 + 4432061591
13 ??? 0x00000001082b9624 0x0 + 4432041508
14 ??? 0x000000010b0c22c4 0x0 + 4480312004
15 ??? 0x000000010b0c014f 0x0 + 4480303439
16 ??? 0x000000010b0bb4f6 0x0 + 4480283894
17 ??? 0x000000010b0bb036 0x0 + 4480282678
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Semaphore in Ada

This is an assignment and I have been asked to implement a Semaphore in Ada as the description below.
However I have implemented the Semaphore.adb and called this Semaphore in the producerconsumer_sem.adb which I created.
I get some output which is the following.
I'm not sure if my initialization of semaphore is correct S: CountingSemaphore(1,1);.
I don't know where I call the S.wait and S.Signal now i randomly called the S.wait before Producer put item in the buffer X := I; and the S.Signal after the X := I;.
Is this the correct way?
Producer-Consumer Problem
The program producerconsumer.adb implements a non-reliable implemen-
tation of the producer-consumer problem, where data is likely be lost. In
the following, you will use three different communication mechanisms to
achieve a reliable implementation of the producer-consumer problem.
Semaphore
The Ada language does not directly provide library functions for a semaphore.
However, semaphores can be implemented by means of a protected object. Create a package specification Semaphore in the file Semaphores.ads
and the corresponding package body in the file Semaphores.adb that
implements a counting semaphore. Skeletons for the package are available on the course page.
Use the semaphore package for a reliable implementation of the producer-
consumer problem. Modify the file producerconsumer.adb and save the
final code as producerconsumer_sem.adb. In order to use the semaphore
package it shall be installed in the same directory as producerconsumer_sem.adb.
It can then be accessed by
with Semaphores;
use Semaphores;
The Output:
OutPut:
1
1
1
2
2
3
4
4
5
6
6
7
7
8
9
9
9
10
11
11
11
12
12
13
13
13
14
15
15
16
16
17
18
18
18
19
20
20
21
21
22
22
23
24
24
24
24
25
25
26
27
27
28
29
29
30
30
31
31
32
32
33
33
33
34
35
35
35
36
36
37
37
37
38
38
38
39
40
40
40
The package
package Semaphores is
protected type CountingSemaphore(Max: Natural; Initial: Natural) is
entry Wait;
entry Signal;
private
Count : Natural := Initial;
MaxCount : Natural := Max;
end CountingSemaphore;
end Semaphores;
The Semaphore I implemented semaphores.adb.
package body Semaphores is
protected body CountingSemaphore is
entry Wait when Count > 0 is
begin
Count := Count - 1;
end Wait;
entry Signal when Count < MaxCount is
begin
Count := Count + 1;
end Signal;
end CountingSemaphore;
end Semaphores;
The producerconsumer_sem.adb
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Real_Time;
use Ada.Real_Time;
with Ada.Numerics.Discrete_Random;
with Semaphores;
use Semaphores;
procedure ProducerConsumer_sem is
X : Integer; -- Shared Variable
N : constant Integer := 40; -- Number of produced and comsumed variables
S: CountingSemaphore(1,1);
--S1: CountingSemaphore(1,1);
pragma Volatile(X); -- For a volatile object all reads and updates of
-- the object as a whole are performed directly
-- to memory (Ada Reference Manual, C.6)
--Random Delays
subtype Delay_Interval is Integer range 50..250;
package Random_Delay is new Ada.Numerics.Discrete_Random
(Delay_Interval);
use Random_Delay;
G : Generator;
task Producer;
task Consumer;
task body Producer is
Next : Time;
begin
Next := Clock;
for I in 1..N loop
-- Write to X
S.Wait;
X := I;
S.Signal;
--Next 'Release' in 50..250ms
Next := Next + Milliseconds(Random(G));
Put_Line(Integer'Image(X));
delay until Next;
end loop;
end;
task body Consumer is
Next : Time;
begin
Next := Clock;
for I in 1..N loop
-- Read from X
S.Wait;
Put_Line(Integer'Image(X));
S.Signal;
Next := Next + Milliseconds(Random(G));
delay until Next;
end loop;
end;
begin -- main task
null;
end ProducerConsumer_sem;
On macOS, with FSF GCC 7.1.0 and GNAT GPL 2017, I changed your Put_Lines to Puts and got pretty-much the answer you state in the question.
The question says to create Semaphore.ads, .adb. This will work on Windows, and may work on macOS, but won’t work on Linux, because of GNAT’s file naming convention (see the end of this; it’s a good idea to get into the habit of using lower-case file names).
If you want to ensure that only one task has access to X at a time, I don’t think there’s much wrong with your Wait, Signal calls, though when I put a delay 0.1 at the beginning of Producer, the first value output was 151619216 (because X isn’t initialized). However! if the point is to communicate one update to X at a time (as implied by the names producer/consumer), you should
initialize the semaphore with a count of 0 (and a max of 1). This makes it a binary semaphore.
in Consumer, Wait only (i.e. remove the Signal)
in Producer, Signal only (i.e. remove the Wait). Also, remove the Put to avoid confusion!

How to handle a complex set of nested for loops vb.net

So I'm struggling to wrap my head around something I'm trying to write. Nest for-next loops are clearly the only way to go (as far as I can tell) but I just can't get any sort of pseudo code worked out. My problem is this, given a fixed number (lets say 100 for simplicity) I want to iterate through all combinations of sets of numbers upto 5 that totals 100. Lets say in steps of 5. So to be clear I would want to run the following first few example:
100
95 - 5
90 - 10
---
10 - 90
5 - 95
90 - 5 - 5
85 - 5 - 10
80 - 5 - 15
---
5 - 5 - 85
85 - 10 - 5
80 - 10 - 10
75 - 10 - 15
---
---
80 - 5 - 5 - 5 - 5
75 - 5 - 5 - 5 - 10
---
Hopefully that give you the idea of my my target is. My problem is that I just can't work out an effective way to program. I'm pretty competent in actually writing code (usually) but every time I sit down and do this I end up with 10's of nested for-next loops that just don't work!
To remove that nesting problem there's a simple approach : use a queue or a stack.
Here's some pseudo-code:
// add 1 item to start with in the queue
while(queue.Count > 0)
{
// 1. dequeue item from queue
// 2. do your work on it
// 3. if there's another combination emerging from step 2, enqueue it in the queue
}
// 4. this point will be reached once finished
Using a custom type to store whatever information you need for that job and by having a single loop instead of many should help you tackle the problem relatively quickly :D

Pulling from a very very specific location imbedded in a text file

I finished every piece of code in my program save for one tid bit, how to pull two numbers from a text file. I know how to pull lines, I know how to pull search strings, but I cant figure out this one to save my life.
Anyways here is a sample of the automatically generated text that I need to pull from...
.......................................................................
Applications Memory Usage (kB):
Uptime: 6089044 Realtime: 6089040
** MEMINFO in pid 764 [com.lookout] **
native dalvik other total
size: 27908 8775 N/A 36683
allocated: 3240 4216 N/A 7456
free: 24115 4559 N/A 28674
(Pss): 1454 1142 6524 *9120*
(priv dirty): 1436 628 5588 *7652*
Objects
Views: 0 ViewRoots: 0
AppContexts: 0 Activities: 0
Assets: 3 AssetManagers: 3
Local Binders: 15 Proxy Binders: 41
Death Recipients: 3
OpenSSL Sockets: 0
SQL
heap: 98 MEMORY_USED: 98
PAGECACHE_OVERFLOW: 16 MALLOC_SIZE: 50
DATABASES
pgsz dbsz Lookaside(b) Dbname
1 14 120 google_analytics.db
Asset Allocations
zip:/system/app/com.lookout_6.0.1_r8234_Release.apk:/resources.arsc: 161K
.............................................................................
The two numbers that I need out of this are the two ones that I put in the **'s (the asterisks are not normally there). These numbers will be different every time this sheet is generated, and the number placement might be different as well as some of the numbers could have 4 digits, 5 digits, or 6 digits.
If anyone could shed any light on the subject it would be greatly appreciated
Thanks,
Zach
You just need to read in the last word of the line and convert it to a number. Use String.LastIndexOf to find the last space " " in the file and read the data from that point forwards.
Dim line as String = " (Pss): 1454 1142 6524 9120"
Dim value as Integer
If line.IndexOf("(Pss)") > 0 Then
value = CInt(line.Substring(line.LastIndexOf(" ") + 1))
End If