Displaying environment variables in assembly language - parsing

I am trying to understand how assembly works by making a basic program to display environement variables like
C code :
int main(int ac, char **av, char **env)
{
int x;
int y;
y = -1;
while (env[++y])
{
x = -1;
while (env[y][++x])
{
write(1, &(env[y][x]), 1);
}
}
return (0);
}
I compiled that with gcc -S (on cygwin64) to see how to do, and wrote it my own way (similar but not same), but it did not work...
$>gcc my_av.s && ./a.exe
HOMEPATH=\Users\hadrien▒2▒p
My assembly code :
.file "test.c"
.LC0:
.ascii "\n\0"
.LC1:
.ascii "\033[1;31m.\033[0m\0"
.LC2:
.ascii "\033[1;31m#\033[0m\0"
.LCtest0:
.ascii "\033[1;32mdebug\033[0m\0"
.LCtest1:
.ascii "\033[1;31mdebug\033[0m\0"
.LCtest2:
.ascii "\033[1;34mdebug\033[0m\0"
.def main; .scl 2; .type 32; .endef
main:
/* initialisation du main */
pushq %rbp
movq %rsp, %rbp
subq $48, %rsp
movl %ecx, 16(%rbp) /* int argc */
movq %rdx, 24(%rbp) /* char **argv */
movq %r8, 32(%rbp) /* char **env */
/* saut de ligne */
/* write init */
movl $1, %r8d /* write size */
movl $1, %ecx /* sortie standart */
leaq .LC0(%rip), %rdx
/* write */
call write
/* debut du code */
movl $-1, -8(%rbp) /* y = -1 */
jmp .Loop_1_condition
.Loop_1_body:
movl $-1, -4(%rbp)
jmp .Loop_2_condition
.Loop_2_body:
/* affiche le charactere */
movl $1, %r8d
movl $1, %ecx
call write
.Loop_2_condition:
addl $1, -4(%rbp) /* x = -1 */
movl -8(%rbp), %eax
cltq
addq 32(%rbp), %rax
movq (%rax), %rax
movq %rax, %rdx
movl -4(%rbp), %eax
cltq
addq %rdx, %rax
movq %rax, %rdx
movq (%rax), %rax
cmpq $0, %rax
jne .Loop_2_body
/* saut de ligne */
movl $1, %r8d /* write size */
movl $1, %ecx /* sortie standart */
leaq .LC0(%rip), %rdx
call write
.Loop_1_condition:
addl $1, -8(%rbp) /* ++y */
movl -8(%rbp), %eax
cltq /* passe eax en 64bits */
addq 32(%rbp), %rax
movq (%rax), %rax
cmpq $0, %rax
jne .Loop_1_body
movl $1, %r8d /* write size */
movl $1, %ecx /* sortie standart */
leaq .LC0(%rip), %rdx
call write
/* fin du programme */
movl $0, %eax /* return (0) */
addq $48, %rsp
popq %rbp
ret
.def write; .scl 2; .type 32; .endef
Could someone explain me what is wrong with this code please ?
Also, while trying to solve the problem i tired to replace $0 by $97 in cmpq operation, thinking it would stop on 'a' character but it didn't... Why ?

You have a few issues. In this code (loop2) you have:
addq %rdx, %rax
movq %rax, %rdx
movq (%rax), %rax
cmpq $0, %rax
movq (%rax), %rax has read the next 8 characters in %rax. You are only interested in the first character. One way to achieve this is to compare the least significant byte in %rax with 0. You can use cmpb and use the %al register:
cmpb $0, %al
The biggest issue though is understanding that char **env is a pointer to array of char * .You first need to get the base pointer for the array, then that base pointer is indexed with y. The indexing looks something like basepointer + (y * 8) . You need to multiply y by 8 because each pointer is 8 bytes wide. The pointer at that location will be the char * for a particular environment string. Then you can index each character in the string array until you find a NUL (0) terminating character.
I've amended the code slightly and added comments on the few lines I changed:
.file "test.c"
.LC0:
.ascii "\x0a\0"
.LC1:
.ascii "\033[1;31m.\033[0m\0"
.LC2:
.ascii "\033[1;31m#\033[0m\0"
.LCtest0:
.ascii "\033[1;32mdebug\033[0m\0"
.LCtest1:
.ascii "\033[1;31mdebug\033[0m\0"
.LCtest2:
.ascii "\033[1;34mdebug\033[0m\0"
.def main; .scl 2; .type 32; .endef
main:
/* initialisation du main */
pushq %rbp
movq %rsp, %rbp
subq $48, %rsp
movl %ecx, 16(%rbp) /* int argc */
movq %rdx, 24(%rbp) /* char **argv */
movq %r8, 32(%rbp) /* char **env */
/* saut de ligne */
/* write init */
movl $1, %r8d /* write size */
movl $1, %ecx /* sortie standart */
leaq .LC0(%rip), %rdx
/* write */
call write
/* debut du code */
movl $-1, -8(%rbp) /* y = -1 */
jmp .Loop_1_condition
.Loop_1_body:
movl $-1, -4(%rbp)
jmp .Loop_2_condition
.Loop_2_body:
/* affiche le charactere */
movl $1, %r8d
movl $1, %ecx
call write
.Loop_2_condition:
addl $1, -4(%rbp) /* x = -1 */
movl -8(%rbp), %eax /* get y index */
cltq
movq 32(%rbp), %rbx /* get envp (pointer to element 0 of char * array) */
movq (%rbx,%rax,8), %rdx /* get pointer at envp+y*8
pointers are 8 bytes wide */
movl -4(%rbp), %eax /* get x */
cltq
leaq (%rdx, %rax), %rdx /* Get current character's address */
cmpb $0, (%rdx) /* Compare current byte to char 0
using cmpq will compare the next 8 bytes */
jne .Loop_2_body
/* saut de ligne */
movl $1, %r8d /* write size */
movl $1, %ecx /* sortie standart */
leaq .LC0(%rip), %rdx
call write
.Loop_1_condition:
addl $1, -8(%rbp) /* ++y */
movl -8(%rbp), %eax
cltq /* passe eax en 64bits */
movq 32(%rbp), %rbx /* get envp (pointer to element 0 of char * array) */
movq (%rbx,%rax,8), %rax /* get pointer at envp+y*8
pointers are 8 bytes wide */
cmpq $0, %rax /* Compare to NULL ptr */
jne .Loop_1_body
movl $1, %r8d /* write size */
movl $1, %ecx /* sortie standart */
leaq .LC0(%rip), %rdx
call write
/* fin du programme */
movl $0, %eax /* return (0) */
addq $48, %rsp
popq %rbp
ret
.def write; .scl 2; .type 32; .endef

Related

What algorithm is used in [NSString containString:] this function in ObjC?

I want to make a app with addressbook, which needs to add search feature.
I hope the search feature can support string matching, and I found the [NSString containString:] this function in NSString class.
In order to efficiently, I want to use a well String Matching Algorithm to achieve it, as KMP. So I want to know what algorithm is used in this function. And where can I look over the source code of NSString function?
Thx.
The assembly is the following:
Foundation`-[NSString containsString:]:
-> 0x10a128954 <+0>: pushq %rbp
0x10a128955 <+1>: movq %rsp, %rbp
0x10a128958 <+4>: pushq %r15
0x10a12895a <+6>: pushq %r14
0x10a12895c <+8>: pushq %rbx
0x10a12895d <+9>: pushq %rax
0x10a12895e <+10>: movq %rdx, %r14
0x10a128961 <+13>: movq %rdi, %rbx
0x10a128964 <+16>: movq 0x1836d5(%rip), %rsi ; "length"
0x10a12896b <+23>: movq 0x19ddee(%rip), %r15 ; (void *)0x000000010a4bb800: objc_msgSend
0x10a128972 <+30>: callq *%r15
0x10a128975 <+33>: movq 0x185dc4(%rip), %rsi ; "rangeOfString:options:range:locale:"
0x10a12897c <+40>: movq $0x0, (%rsp)
0x10a128984 <+48>: xorl %ecx, %ecx
0x10a128986 <+50>: xorl %r8d, %r8d
0x10a128989 <+53>: movq %rbx, %rdi
0x10a12898c <+56>: movq %r14, %rdx
0x10a12898f <+59>: movq %rax, %r9
0x10a128992 <+62>: callq *%r15
0x10a128995 <+65>: movabsq $0x7fffffffffffffff, %rcx ; imm = 0x7FFFFFFFFFFFFFFF
0x10a12899f <+75>: cmpq %rcx, %rax
0x10a1289a2 <+78>: setne %al
0x10a1289a5 <+81>: addq $0x8, %rsp
0x10a1289a9 <+85>: popq %rbx
0x10a1289aa <+86>: popq %r14
0x10a1289ac <+88>: popq %r15
0x10a1289ae <+90>: popq %rbp
0x10a1289af <+91>: retq
It is essentially the following algorithm:
- (bool)containsString:(NSString *)stringToFind {
if (stringToFind && stringToFind.length < self) {
return (typeof(NSNotFound))[self rangeOfString:stringToFind options:NSLiteralSearch range:NSMakeRange(0, self.length) locale:nil].location != NSNotFound;
}
return false;
}
P.S. It does NOT check if the string is nil or check its length. It does exactly:
- (bool)containsString:(NSString *)stringToFind {
return (typeof(NSNotFound))[self rangeOfString:stringToFind options:NSLiteralSearch range:NSMakeRange(0, self.length) locale:nil].location != NSNotFound;
}
with no safety checks. I don't know why I decided to add the checks but w/e..
Range of String has the following assembly:
Foundation`-[NSString rangeOfString:options:range:locale:]:
-> 0x10a031cfd <+0>: pushq %rbp
0x10a031cfe <+1>: movq %rsp, %rbp
0x10a031d01 <+4>: pushq %r15
0x10a031d03 <+6>: pushq %r14
0x10a031d05 <+8>: pushq %r13
0x10a031d07 <+10>: pushq %r12
0x10a031d09 <+12>: pushq %rbx
0x10a031d0a <+13>: subq $0x48, %rsp
0x10a031d0e <+17>: movq %r9, %r15
0x10a031d11 <+20>: movq %r8, %r14
0x10a031d14 <+23>: movq %rcx, -0x40(%rbp)
0x10a031d18 <+27>: movq %rdx, %r13
0x10a031d1b <+30>: movq %rsi, -0x48(%rbp)
0x10a031d1f <+34>: movq %rdi, %r12
0x10a031d22 <+37>: movq 0x27a317(%rip), %rsi ; "length"
0x10a031d29 <+44>: movq 0x294a30(%rip), %rbx ; (void *)0x000000010a4bb800: objc_msgSend
0x10a031d30 <+51>: movq %r13, %rdi
0x10a031d33 <+54>: callq *%rbx
0x10a031d35 <+56>: movq %rax, -0x50(%rbp)
0x10a031d39 <+60>: movq 0x27a300(%rip), %rsi ; "length"
0x10a031d40 <+67>: movq %r12, %rdi
0x10a031d43 <+70>: callq *%rbx
0x10a031d45 <+72>: movq %rax, %rbx
0x10a031d48 <+75>: subq %r15, %rax
0x10a031d4b <+78>: jb 0x10a031d56 ; <+89>
0x10a031d4d <+80>: cmpq %r14, %rax
0x10a031d50 <+83>: jae 0x10a031e07 ; <+266>
0x10a031d56 <+89>: callq 0x10a239912 ; symbol stub for: __CFStringNoteErrors
0x10a031d5b <+94>: testb %al, %al
0x10a031d5d <+96>: je 0x10a031e07 ; <+266>
0x10a031d63 <+102>: movl $0x6, %edi
0x10a031d68 <+107>: callq 0x10a2396b4 ; symbol stub for: _CFExecutableLinkedOnOrAfter
0x10a031d6d <+112>: testb %al, %al
0x10a031d6f <+114>: je 0x10a031dc5 ; <+200>
0x10a031d71 <+116>: movq 0x281420(%rip), %rax ; (void *)0x000000010ac5a358: NSException
0x10a031d78 <+123>: movq %rax, -0x58(%rbp)
0x10a031d7c <+127>: movq 0x294325(%rip), %rax ; (void *)0x000000010ac74b38: NSRangeException
0x10a031d83 <+134>: movq (%rax), %rax
0x10a031d86 <+137>: movq %rax, -0x60(%rbp)
0x10a031d8a <+141>: movq %r12, %rdi
0x10a031d8d <+144>: movq -0x48(%rbp), %rsi
0x10a031d91 <+148>: callq 0x10a11f7e0 ; _NSMethodExceptionProem
0x10a031d96 <+153>: movq %rax, %r8
0x10a031d99 <+156>: movq 0x27a288(%rip), %rsi ; "raise:format:"
0x10a031da0 <+163>: movq %rbx, 0x8(%rsp)
0x10a031da5 <+168>: movq %r15, (%rsp)
0x10a031da9 <+172>: leaq 0x2a4e40(%rip), %rcx ; #"%#: Range {%lu, %lu} out of bounds; string length %lu"
0x10a031db0 <+179>: xorl %eax, %eax
0x10a031db2 <+181>: movq -0x58(%rbp), %rdi
0x10a031db6 <+185>: movq -0x60(%rbp), %rdx
0x10a031dba <+189>: movq %r14, %r9
0x10a031dbd <+192>: callq *0x29499d(%rip) ; (void *)0x000000010a4bb800: objc_msgSend
0x10a031dc3 <+198>: jmp 0x10a031e07 ; <+266>
0x10a031dc5 <+200>: movb 0x29326d(%rip), %al ; rangeOfString:options:range:locale:.warnonce
0x10a031dcb <+206>: testb %al, %al
0x10a031dcd <+208>: jne 0x10a031e07 ; <+266>
0x10a031dcf <+210>: movb $0x1, 0x293262(%rip) ; compare:options:range:locale:.localeClass + 7
0x10a031dd6 <+217>: movq %r12, %rdi
0x10a031dd9 <+220>: movq -0x48(%rbp), %rsi
0x10a031ddd <+224>: callq 0x10a11f7e0 ; _NSMethodExceptionProem
0x10a031de2 <+229>: movq %rax, %rbx
0x10a031de5 <+232>: movq %r14, %rdi
0x10a031de8 <+235>: movq %r15, %rsi
0x10a031deb <+238>: callq 0x10a1212f0 ; NSStringFromRange
0x10a031df0 <+243>: movq %rax, %rcx
0x10a031df3 <+246>: leaq 0x2a4e36(%rip), %rdi ; #"*** %#: Invalid range %#; this will become an exception for apps linked on SnowLeopard. Warning shown once per app execution."
0x10a031dfa <+253>: xorl %eax, %eax
0x10a031dfc <+255>: movq %rbx, %rsi
0x10a031dff <+258>: movq %rcx, %rdx
0x10a031e02 <+261>: callq 0x10a06c78a ; NSLog
0x10a031e07 <+266>: testq %r13, %r13
0x10a031e0a <+269>: jne 0x10a031e5e ; <+353>
0x10a031e0c <+271>: callq 0x10a239912 ; symbol stub for: __CFStringNoteErrors
0x10a031e11 <+276>: testb %al, %al
0x10a031e13 <+278>: je 0x10a031e5e ; <+353>
0x10a031e15 <+280>: movq 0x28137c(%rip), %rax ; (void *)0x000000010ac5a358: NSException
0x10a031e1c <+287>: movq %rax, -0x58(%rbp)
0x10a031e20 <+291>: movq 0x294241(%rip), %rax ; (void *)0x000000010ac74b40: NSInvalidArgumentException
0x10a031e27 <+298>: movq (%rax), %rax
0x10a031e2a <+301>: movq %rax, -0x60(%rbp)
0x10a031e2e <+305>: movq %r12, %rdi
0x10a031e31 <+308>: movq -0x48(%rbp), %rsi
0x10a031e35 <+312>: callq 0x10a11f7e0 ; _NSMethodExceptionProem
0x10a031e3a <+317>: movq %rax, %rbx
0x10a031e3d <+320>: movq 0x27a1e4(%rip), %rsi ; "raise:format:"
0x10a031e44 <+327>: leaq 0x2a4dc5(%rip), %rcx ; #"%#: nil argument"
0x10a031e4b <+334>: xorl %eax, %eax
0x10a031e4d <+336>: movq -0x58(%rbp), %rdi
0x10a031e51 <+340>: movq -0x60(%rbp), %rdx
0x10a031e55 <+344>: movq %rbx, %r8
0x10a031e58 <+347>: callq *0x294902(%rip) ; (void *)0x000000010a4bb800: objc_msgSend
0x10a031e5e <+353>: movq 0x10(%rbp), %r9
0x10a031e62 <+357>: movq -0x40(%rbp), %rcx
0x10a031e66 <+361>: testb $0x4, %ch
0x10a031e69 <+364>: jne 0x10a031ebe ; <+449>
0x10a031e6b <+366>: movabsq $0x7fffffffffffffff, %rbx ; imm = 0x7FFFFFFFFFFFFFFF
0x10a031e75 <+376>: xorl %edx, %edx
0x10a031e77 <+378>: testq %r15, %r15
0x10a031e7a <+381>: je 0x10a031ede ; <+481>
0x10a031e7c <+383>: cmpq $0x0, -0x50(%rbp)
0x10a031e81 <+388>: je 0x10a031ede ; <+481>
0x10a031e83 <+390>: leaq (,%rcx,8), %r8
0x10a031e8b <+398>: notl %r8d
0x10a031e8e <+401>: andq $0x10, %r8
0x10a031e92 <+405>: orq %rcx, %r8
0x10a031e95 <+408>: leaq -0x38(%rbp), %rax
0x10a031e99 <+412>: movq %rax, (%rsp)
0x10a031e9d <+416>: movq %r12, %rdi
0x10a031ea0 <+419>: movq %r13, %rsi
0x10a031ea3 <+422>: movq %r14, %rdx
0x10a031ea6 <+425>: movq %r15, %rcx
0x10a031ea9 <+428>: callq 0x10a239354 ; symbol stub for: CFStringFindWithOptionsAndLocale
0x10a031eae <+433>: xorl %edx, %edx
0x10a031eb0 <+435>: testb %al, %al
0x10a031eb2 <+437>: je 0x10a031ede ; <+481>
0x10a031eb4 <+439>: movq -0x38(%rbp), %rbx
0x10a031eb8 <+443>: movq -0x30(%rbp), %rdx
0x10a031ebc <+447>: jmp 0x10a031ede ; <+481>
0x10a031ebe <+449>: movq 0x27c873(%rip), %rsi ; "_rangeOfRegularExpressionPattern:options:range:locale:"
0x10a031ec5 <+456>: movq %r9, (%rsp)
0x10a031ec9 <+460>: movq %r12, %rdi
0x10a031ecc <+463>: movq %r13, %rdx
0x10a031ecf <+466>: movq %r14, %r8
0x10a031ed2 <+469>: movq %r15, %r9
0x10a031ed5 <+472>: callq *0x294885(%rip) ; (void *)0x000000010a4bb800: objc_msgSend
0x10a031edb <+478>: movq %rax, %rbx
0x10a031ede <+481>: movq %rbx, %rax
0x10a031ee1 <+484>: addq $0x48, %rsp
0x10a031ee5 <+488>: popq %rbx
0x10a031ee6 <+489>: popq %r12
0x10a031ee8 <+491>: popq %r13
0x10a031eea <+493>: popq %r14
0x10a031eec <+495>: popq %r15
0x10a031eee <+497>: popq %rbp
0x10a031eef <+498>: retq
It runs a regular expression to check if one string has another AND it has safety checks..
The iOS Foundation is Apple's proprietary code, so there is little chance you can see NSString implementation code legally.
What I would do in your situation is:
Build and run some benchmarks for the [NSString containString:] function (a decent list of string/pattern pairs).
If the results are not acceptable for you - try to find an alternative implementation of string search (there is a lot of open-source C code for this), run the same benchmarks on that implementation and compare with original results.

Simulator crashes when launching in xcode and the issue is in view.controller.init

I've been teaching myself Swift and only a few days in. I've honestly done very little to the code and not sure what is going on. I cannot find a similar thread on stackoverflow with the same issue.
This is all I have written so far in the ViewController.swift:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var calcNum: UILabel!
var middleOfTyping = false
#IBAction func numButton(sender: UIButton) {
let digit = sender.currentTitle!
if middleOfTyping {
calcNum.text = calcNum.text! + digit
} else {
calcNum.text = digit
}
}
}
When I try launching the simulator, the simulator crashes and gives me this code within Thread 1 - 0 ViewController.init :
Calculator Take 2`Calculator_Take_2.ViewController.init (Calculator_Take_2.ViewController.Type)(coder : __ObjC.NSCoder) -> Swift.Optional<Calculator_Take_2.ViewController>:
0x10b542b00 <+0>: pushq %rbp
0x10b542b01 <+1>: movq %rsp, %rbp
0x10b542b04 <+4>: subq $0x70, %rsp
0x10b542b08 <+8>: movq %rdi, -0x10(%rbp)
0x10b542b0c <+12>: movq %rsi, -0x8(%rbp)
-> 0x10b542b10 <+16>: movq $0x0, -0x18(%rbp)
0x10b542b18 <+24>: movq -0x18(%rbp), %rax
0x10b542b1c <+28>: movq 0x363d(%rip), %rcx ; direct field offset for Calculator_Take_2.ViewController.calcNum
0x10b542b23 <+35>: movq %rsi, %rdx
0x10b542b26 <+38>: addq %rcx, %rdx
0x10b542b29 <+41>: movq %rdi, -0x30(%rbp)
0x10b542b2d <+45>: movq %rdx, %rdi
0x10b542b30 <+48>: movq %rsi, -0x38(%rbp)
0x10b542b34 <+52>: movq %rax, %rsi
0x10b542b37 <+55>: movq %rax, -0x40(%rbp)
0x10b542b3b <+59>: callq 0x10b5436f8 ; symbol stub for: swift_unknownWeakInit
0x10b542b40 <+64>: movq -0x40(%rbp), %rdi
0x10b542b44 <+68>: callq 0x10b5436e0 ; symbol stub for: swift_unknownRelease
0x10b542b49 <+73>: movq 0x3618(%rip), %rax ; direct field offset for Calculator_Take_2.ViewController.middleOfTyping
0x10b542b50 <+80>: movq -0x38(%rbp), %rcx
0x10b542b54 <+84>: movb $0x0, (%rcx,%rax)
0x10b542b58 <+88>: movq $0x0, -0x8(%rbp)
0x10b542b60 <+96>: movq %rcx, -0x48(%rbp)
0x10b542b64 <+100>: callq 0x10b542620 ; type metadata accessor for Calculator_Take_2.ViewController
0x10b542b69 <+105>: leaq -0x28(%rbp), %rdi
0x10b542b6d <+109>: movq -0x48(%rbp), %rcx
0x10b542b71 <+113>: movq %rcx, -0x28(%rbp)
0x10b542b75 <+117>: movq %rax, -0x20(%rbp)
0x10b542b79 <+121>: movq 0x3448(%rip), %rsi ; "initWithCoder:"
0x10b542b80 <+128>: movq -0x30(%rbp), %rax
0x10b542b84 <+132>: movq %rax, %rdx
0x10b542b87 <+135>: callq 0x10b543692 ; symbol stub for: objc_msgSendSuper2
0x10b542b8c <+140>: cmpq $0x0, %rax
0x10b542b92 <+146>: sete %r8b
0x10b542b96 <+150>: xorb $0x1, %r8b
0x10b542b9a <+154>: testb $0x1, %r8b
0x10b542b9e <+158>: movq %rax, -0x50(%rbp)
0x10b542ba2 <+162>: jne 0x10b542ba6 ; <+166> at ViewController.swift
0x10b542ba4 <+164>: jmp 0x10b542bda ; <+218> at ViewController.swift
0x10b542ba6 <+166>: movq -0x50(%rbp), %rax
0x10b542baa <+170>: movq %rax, -0x8(%rbp)
0x10b542bae <+174>: movq %rax, %rdi
0x10b542bb1 <+177>: movq %rax, -0x58(%rbp)
0x10b542bb5 <+181>: callq 0x10b54369e ; symbol stub for: objc_retain
0x10b542bba <+186>: movq -0x30(%rbp), %rdi
0x10b542bbe <+190>: movq %rax, -0x60(%rbp)
0x10b542bc2 <+194>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542bc7 <+199>: movq -0x58(%rbp), %rdi
0x10b542bcb <+203>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542bd0 <+208>: movq -0x58(%rbp), %rax
0x10b542bd4 <+212>: movq %rax, -0x68(%rbp)
0x10b542bd8 <+216>: jmp 0x10b542bf4 ; <+244> at ViewController.swift
0x10b542bda <+218>: movq -0x30(%rbp), %rdi
0x10b542bde <+222>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542be3 <+227>: xorl %eax, %eax
0x10b542be5 <+229>: movl %eax, %edi
0x10b542be7 <+231>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542bec <+236>: xorl %eax, %eax
0x10b542bee <+238>: movl %eax, %edi
0x10b542bf0 <+240>: movq %rdi, -0x68(%rbp)
0x10b542bf4 <+244>: movq -0x68(%rbp), %rax
0x10b542bf8 <+248>: addq $0x70, %rsp
0x10b542bfc <+252>: popq %rbp
0x10b542bfd <+253>: retq
xcode claims that the breakpoint is at "0x10b542b10 <+16>: movq $0x0, -0x18(%rbp)". I am not sure what any of this means nor how to fix it.
I tried to "undo" all the code I changed in my Main.storyboard, but even when I do that, the code that once worked does not work anymore either and produces the same error, so I am wondering if it is an issue with xCode itself (restarting does not help either).
Any help would be greatly appreciated! Thank you so much!
Did you connect the #IBOutlet weak var calcNum to your label on the view. I.e. is the circle next to it filled? If not connect them, by dragging a line from the circle to the label.

MR_importFromObject method is not working in XCode7.1 beta (Swift 2.0)

I want to create entity from dictionary using MR_ImportFromObject method.
It worked before I update Xcode 6 to 7.
But when I use Xcode7, ImportFromObject method is not working.
Every call that method, willImport Delegate method is not called and application is crashed.
But ImportFromArray method is working very well.
Here is error message. I think the points are "swift_bridgeNonVerbatimFromObjectiveC" and "value type is not bridged to Objective-C".
libswiftCore.dylib`swift_bridgeNonVerbatimFromObjectiveC:
0x1060d4d50 <+0>: pushq %rbp
0x1060d4d51 <+1>: movq %rsp, %rbp
0x1060d4d54 <+4>: pushq %r15
0x1060d4d56 <+6>: pushq %r14
0x1060d4d58 <+8>: pushq %r12
0x1060d4d5a <+10>: pushq %rbx
0x1060d4d5b <+11>: movq %rdx, %r14
0x1060d4d5e <+14>: movq %rsi, %rbx
0x1060d4d61 <+17>: movq %rdi, %r15
0x1060d4d64 <+20>: leaq 0x54a15(%rip), %rsi ; _TMpSs21_ObjectiveCBridgeable
0x1060d4d6b <+27>: movq %rbx, %rdi
0x1060d4d6e <+30>: callq 0x1060d4610 ; swift_conformsToProtocol
0x1060d4d73 <+35>: movq %rax, %r12
0x1060d4d76 <+38>: testq %r12, %r12
0x1060d4d79 <+41>: je 0x1060d4dc9 ; <+121>
0x1060d4d7b <+43>: movq %rbx, %rdi
0x1060d4d7e <+46>: movq %rbx, %rsi
0x1060d4d81 <+49>: callq *0x8(%r12)
0x1060d4d86 <+54>: testb %al, %al
0x1060d4d88 <+56>: je 0x1060d4e49 ; <+249>
0x1060d4d8e <+62>: movq %rbx, %rdi
0x1060d4d91 <+65>: movq %rbx, %rsi
0x1060d4d94 <+68>: callq *0x10(%r12)
0x1060d4d99 <+73>: movq %r15, %rdi
0x1060d4d9c <+76>: movq %rax, %rsi
0x1060d4d9f <+79>: callq 0x1060d2100 ; swift_dynamicCastUnknownClass
0x1060d4da4 <+84>: testq %rax, %rax
0x1060d4da7 <+87>: je 0x1060d4e49 ; <+249>
0x1060d4dad <+93>: movq 0x20(%r12), %r8
0x1060d4db2 <+98>: movq %rax, %rdi
0x1060d4db5 <+101>: movq %r14, %rsi
0x1060d4db8 <+104>: movq %rbx, %rdx
0x1060d4dbb <+107>: movq %rbx, %rcx
0x1060d4dbe <+110>: popq %rbx
0x1060d4dbf <+111>: popq %r12
0x1060d4dc1 <+113>: popq %r14
0x1060d4dc3 <+115>: popq %r15
0x1060d4dc5 <+117>: popq %rbp
0x1060d4dc6 <+118>: jmpq *%r8
0x1060d4dc9 <+121>: movq (%rbx), %rcx
0x1060d4dcc <+124>: xorl %eax, %eax
0x1060d4dce <+126>: cmpq $0x80, %rcx
0x1060d4dd5 <+133>: cmovbeq %rcx, %rax
0x1060d4dd9 <+137>: cmpq $0xf, %rax
0x1060d4ddd <+141>: jne 0x1060d4df1 ; <+161>
0x1060d4ddf <+143>: testl $0x80ffffff, 0x10(%rbx)
0x1060d4de6 <+150>: jne 0x1060d4e49 ; <+249>
0x1060d4de8 <+152>: leaq 0x54959(%rip), %r12 ; protocol witness table for Swift._BridgeableMetatype : Swift._ObjectiveCBridgeable in Swift
0x1060d4def <+159>: jmp 0x1060d4d7b ; <+43>
0x1060d4df1 <+161>: cmpq $0xd, %rax
0x1060d4df5 <+165>: jne 0x1060d4e49 ; <+249>
0x1060d4df7 <+167>: movq 0x8(%rbx), %rax
0x1060d4dfb <+171>: movq (%rax), %rcx
0x1060d4dfe <+174>: xorl %eax, %eax
0x1060d4e00 <+176>: cmpq $0x80, %rcx
0x1060d4e07 <+183>: cmovbeq %rcx, %rax
0x1060d4e0b <+187>: leaq 0x54936(%rip), %r12 ; protocol witness table for Swift._BridgeableMetatype : Swift._ObjectiveCBridgeable in Swift
0x1060d4e12 <+194>: cmpq $0x3f, %rax
0x1060d4e16 <+198>: jg 0x1060d4e33 ; <+227>
0x1060d4e18 <+200>: cmpq $0xf, %rax
0x1060d4e1c <+204>: ja 0x1060d4d7b ; <+43>
0x1060d4e22 <+210>: movl $0xb706, %ecx
0x1060d4e27 <+215>: btq %rax, %rcx
0x1060d4e2b <+219>: jae 0x1060d4d7b ; <+43>
0x1060d4e31 <+225>: jmp 0x1060d4e49 ; <+249>
0x1060d4e33 <+227>: leaq -0x40(%rax), %rcx
0x1060d4e37 <+231>: cmpq $0x2, %rcx
0x1060d4e3b <+235>: jb 0x1060d4e49 ; <+249>
0x1060d4e3d <+237>: cmpq $0x80, %rax
0x1060d4e43 <+243>: jne 0x1060d4d7b ; <+43>
0x1060d4e49 <+249>: leaq 0x4467e(%rip), %rax ; "value type is not bridged to Objective-C"
0x1060d4e50 <+256>: movq %rax, 0x86561(%rip) ; gCRAnnotations + 8
0x1060d4e57 <+263>: int3
-> 0x1060d4e58 <+264>: nopl (%rax,%rax)
I changed the MagicalRecord MR_importFromObject Library for now from
id value = [objectData MR_valueForAttribute:primaryAttribute];
if (primaryAttribute != nil)
{
managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
}
to
if (primaryAttribute != nil)
{
id value = [objectData MR_valueForAttribute:primaryAttribute];
managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
}
You can probably put this in a category or extension (swift) on NSManagedObject and use that until MagicalRecord fixes this. That's what I'll do. This fixed this crash for me.
Try disabling the swift compiler optimizations. We had a similar crash unrelated to magical record that was fixed by changing that setting.

getting error "dyld_sim`dyld_fatal_error" after app starts

dyld_sim`dyld_fatal_error:
0x103e63000 <+0>: int3
-> 0x103e63001 <+1>: nop
My app is compile & build successfully but it ends with above error.
There're no other messages (error logs).
I set breakpoints in AppDelegate's didFinishLaunghingWithOptions method and in main.m also. But it never stops there.
My app's first view is always visible and error is coming only after it.
I couldn't find anything regarding this error – how can I solve it? Any specific suggestions.
I also tried this,
change frameworks type from Required to Optional.
But nothing works !!
And yes, I'm using CocoaPods.
Update:
My question isn't matched with any other questions, as both having contradict in titles.
Error which I'm getting - dyld_sim`dyld_fatal_error
Error in duplicate (suggestion) question - dyld`dyld_fatal_error:
Update 2:
Update 3:
Crash log
dyld_sim`dyldbootstrap::rebaseDyld:
0x10f95c002 <+0>: pushq %rbp
0x10f95c003 <+1>: movq %rsp, %rbp
0x10f95c006 <+4>: pushq %r15
0x10f95c008 <+6>: pushq %r14
0x10f95c00a <+8>: pushq %r13
0x10f95c00c <+10>: pushq %r12
0x10f95c00e <+12>: pushq %rbx
0x10f95c00f <+13>: subq $0x18, %rsp
0x10f95c013 <+17>: movq %rsi, %rbx
0x10f95c016 <+20>: movq %rdi, %r14
0x10f95c019 <+23>: movl 0x10(%r14), %r13d
0x10f95c01d <+27>: addq $0x20, %r14
0x10f95c021 <+31>: xorl %eax, %eax
0x10f95c023 <+33>: movq %rax, -0x30(%rbp)
0x10f95c027 <+37>: xorl %eax, %eax
0x10f95c029 <+39>: movq %rax, -0x38(%rbp)
0x10f95c02d <+43>: xorl %r12d, %r12d
0x10f95c030 <+46>: xorl %r15d, %r15d
-> 0x10f95c033 <+49>: movl (%r14), %eax
0x10f95c036 <+52>: cmpl $0xb, %eax
0x10f95c039 <+55>: jne 0x10f95c043 ; <+65>
0x10f95c03b <+57>: movq %r14, %r12
0x10f95c03e <+60>: jmp 0x10f95c0cc ; <+202>
0x10f95c043 <+65>: cmpl $0x19, %eax
0x10f95c046 <+68>: jne 0x10f95c0cc ; <+202>
0x10f95c04c <+74>: leaq 0x8(%r14), %rdi
0x10f95c050 <+78>: leaq 0x192c0(%rip), %rsi ; "__LINKEDIT"
0x10f95c057 <+85>: callq 0x10f9751a2 ; strcmp
0x10f95c05c <+90>: testl %eax, %eax
0x10f95c05e <+92>: movq -0x30(%rbp), %rax
0x10f95c062 <+96>: cmoveq %r14, %rax
0x10f95c066 <+100>: movq %rax, -0x30(%rbp)
0x10f95c06a <+104>: leaq 0x48(%r14), %rax
0x10f95c06e <+108>: movl 0x40(%r14), %ecx
0x10f95c072 <+112>: leaq (%rcx,%rcx,4), %rcx
0x10f95c076 <+116>: shlq $0x4, %rcx
0x10f95c07a <+120>: leaq 0x48(%r14,%rcx), %rcx
0x10f95c07f <+125>: jmp 0x10f95c085 ; <+131>
0x10f95c081 <+127>: addq $0x50, %rax
0x10f95c085 <+131>: cmpq %rcx, %rax
0x10f95c088 <+134>: jae 0x10f95c0b3 ; <+177>
0x10f95c08a <+136>: movzbl 0x40(%rax), %edx
0x10f95c08e <+140>: cmpl $0x6, %edx
0x10f95c091 <+143>: jne 0x10f95c081 ; <+127>
0x10f95c093 <+145>: movq 0x28(%rax), %rdx
0x10f95c097 <+149>: shrq $0x3, %rdx
0x10f95c09b <+153>: testl %edx, %edx
0x10f95c09d <+155>: je 0x10f95c081 ; <+127>
0x10f95c09f <+157>: movq 0x20(%rax), %rsi
0x10f95c0a3 <+161>: addq %rbx, %rsi
0x10f95c0a6 <+164>: addq %rbx, (%rsi)
0x10f95c0a9 <+167>: addq $0x8, %rsi
0x10f95c0ad <+171>: decl %edx
0x10f95c0af <+173>: jne 0x10f95c0a6 ; <+164>
0x10f95c0b1 <+175>: jmp 0x10f95c081 ; <+127>
0x10f95c0b3 <+177>: cmpq $0x0, -0x38(%rbp)
0x10f95c0b8 <+182>: jne 0x10f95c0cc ; <+202>
0x10f95c0ba <+184>: testb $0x2, 0x3c(%r14)
0x10f95c0bf <+189>: movl $0x0, %eax
0x10f95c0c4 <+194>: cmovneq %r14, %rax
0x10f95c0c8 <+198>: movq %rax, -0x38(%rbp)
0x10f95c0cc <+202>: movl 0x4(%r14), %eax
0x10f95c0d0 <+206>: addq %rax, %r14
0x10f95c0d3 <+209>: incl %r15d
0x10f95c0d6 <+212>: cmpl %r13d, %r15d
0x10f95c0d9 <+215>: jne 0x10f95c033 ; <+49>
0x10f95c0df <+221>: movl 0x48(%r12), %esi
0x10f95c0e4 <+226>: movl 0x4c(%r12), %edx
0x10f95c0e9 <+231>: testq %rdx, %rdx
0x10f95c0ec <+234>: je 0x10f95c13d ; <+315>
0x10f95c0ee <+236>: movq -0x38(%rbp), %rax
0x10f95c0f2 <+240>: movq 0x18(%rax), %rax
0x10f95c0f6 <+244>: addq %rbx, %rax
0x10f95c0f9 <+247>: movq -0x30(%rbp), %rcx
0x10f95c0fd <+251>: movq %rcx, %rdi
0x10f95c100 <+254>: movq 0x18(%rdi), %rcx
0x10f95c104 <+258>: addq %rbx, %rcx
0x10f95c107 <+261>: addq %rsi, %rcx
0x10f95c10a <+264>: subq 0x28(%rdi), %rcx
0x10f95c10e <+268>: leaq (%rcx,%rdx,8), %rdx
0x10f95c112 <+272>: movl 0x4(%rcx), %esi
0x10f95c115 <+275>: movl %esi, %edi
0x10f95c117 <+277>: andl $0x6000000, %edi
0x10f95c11d <+283>: cmpl $0x6000000, %edi
0x10f95c123 <+289>: jne 0x10f95c14c ; <+330>
0x10f95c125 <+291>: cmpl $0x10000000, %esi
0x10f95c12b <+297>: jae 0x10f95c15f ; <+349>
0x10f95c12d <+299>: movslq (%rcx), %rsi
0x10f95c130 <+302>: addq %rbx, (%rax,%rsi)
0x10f95c134 <+306>: addq $0x8, %rcx
0x10f95c138 <+310>: cmpq %rdx, %rcx
0x10f95c13b <+313>: jb 0x10f95c112 ; <+272>
0x10f95c13d <+315>: addq $0x18, %rsp
0x10f95c141 <+319>: popq %rbx
0x10f95c142 <+320>: popq %r12
0x10f95c144 <+322>: popq %r13
0x10f95c146 <+324>: popq %r14
0x10f95c148 <+326>: popq %r15
0x10f95c14a <+328>: popq %rbp
0x10f95c14b <+329>: retq
0x10f95c14c <+330>: movl $0x8, %edi
0x10f95c151 <+335>: callq 0x10f9710ea ; __cxa_allocate_exception
0x10f95c156 <+340>: leaq 0x191c5(%rip), %rcx ; "relocation in dyld has wrong size"
0x10f95c15d <+347>: jmp 0x10f95c170 ; <+366>
0x10f95c15f <+349>: movl $0x8, %edi
0x10f95c164 <+354>: callq 0x10f9710ea ; __cxa_allocate_exception
0x10f95c169 <+359>: leaq 0x191d4(%rip), %rcx ; "relocation in dyld has wrong type"
0x10f95c170 <+366>: movq %rcx, (%rax)
0x10f95c173 <+369>: leaq 0x24c56(%rip), %rcx ; typeinfo for char const*
0x10f95c17a <+376>: xorl %edx, %edx
0x10f95c17c <+378>: movq %rax, %rdi
0x10f95c17f <+381>: movq %rcx, %rsi
0x10f95c182 <+384>: callq 0x10f971354 ; __cxa_throw
I had this issue after deleting a bunch of things to try and fix another issue. I was able to fix it by reverting the following:
In Project>Build Settings>Runpath Search Paths, add the following (using the + icon, values are comma separated):
$(inherited), #executable_path/Frameworks, #loader_path/Frameworks
Unfortunately, SO text editor made me write it in a code block.

iOS filtered tableview navigation push UIView, then UIView back causing crash

Did someone meet the same bothering issue? I cannot figure out the UIView will send release message to whom.
Many thanks for any advice.
My test code Strictly follow Apple tableView/Search example code guide. Initial TableView works perfect. and the filtered tableView is triggered to display in UISearchController -> searchResultsController, code is like below.
func updateSearchResultsForSearchController(searchController: UISearchController) {
...
let tableController = self.searchController!.searchResultsController as! FilteredTableViewController
tableController.datasource = self.tableData?.tableFilteredCellRecords
tableController.navController = self.navigationController
tableController.tableView.reloadData()
...
}
In the filtered tableView, Cell row display OK, then click any cell to trigger detail UIView display, code is like below:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let record = self.tableData!.getFilteredTableRecord(indexPath.row)
if(record != nil) {
let detailViewController = DetailViewController()
detailViewController.titleText = record?.title
detailViewController.descText = record?.desc
detailViewController.imgExist = record!.imgview
self.navigationController?.pushViewController(detailViewController, animated: false)
}
}
Then the detail UIView display well, but when click 'Back' button to return TableView, the App crash.
After enable Zombie, the debug report:
(lldb)
Optional("A server with the specified hostname could not be found.")
2015-05-04 22:45:31.687 Swift_UI_programmatically[2057:419330] *** -[UIViewControllerWrapperView release]: message sent to deallocated instance 0x7fdefe0d8250
(lldb)
0x102db5f49 <+489>: callq *0x3062a1(%rip) ; (void *)0x0000000102b08000: objc_msgSend
0x102db5f4f <+495>: jmp 0x102db5f72 ; <+530>
0x102db5f51 <+497>: movq %r14, %rdi
0x102db5f54 <+500>: callq 0x102eaff58 ; symbol stub for: object_getClassName
0x102db5f59 <+505>: movq %rax, %rcx
0x102db5f5c <+508>: leaq 0x32cabd(%rip), %rsi ; #"*** NSForwarding: warning: object %p of class '%s' does not implement forwardInvocation: -- dropping message"
0x102db5f63 <+515>: movl $0x4, %edi
0x102db5f68 <+520>: xorl %eax, %eax
0x102db5f6a <+522>: movq %r14, %rdx
0x102db5f6d <+525>: callq 0x102dfd000 ; CFLog
0x102db5f72 <+530>: movq 0x34b0a7(%rip), %rax ; NSInvocation._retainedArgs
0x102db5f79 <+537>: cmpb $0x0, (%rbx,%rax)
0x102db5f7d <+541>: je 0x102db5fb1 ; <+593>
0x102db5f7f <+543>: movq (%r13), %rax
0x102db5f83 <+547>: testb $-0x80, 0x22(%rax)
0x102db5f87 <+551>: je 0x102db5fb1 ; <+593>
0x102db5f89 <+553>: movq 0x34b080(%rip), %rcx ; NSInvocation._frame
0x102db5f90 <+560>: movq (%rbx,%rcx), %rcx
0x102db5f94 <+564>: movl 0x1c(%rax), %edx
0x102db5f97 <+567>: movzbl 0x20(%rax), %esi
0x102db5f9b <+571>: addq %rdx, %rsi
0x102db5f9e <+574>: movq (%r15,%rsi), %rdi
0x102db5fa2 <+578>: movq (%rcx,%rsi), %rsi
0x102db5fa6 <+582>: movq (%rax), %rax
0x102db5fa9 <+585>: movl 0x10(%rax), %edx
0x102db5fac <+588>: callq 0x102eb04b0 ; symbol stub for: memmove
0x102db5fb1 <+593>: movq 0x34b050(%rip), %rax ; NSInvocation._retdata
0x102db5fb8 <+600>: movq (%rbx,%rax), %r15
0x102db5fbc <+604>: movq 0x34a02d(%rip), %rsi ; "methodReturnType"
0x102db5fc3 <+611>: movq %r12, %rdi
0x102db5fc6 <+614>: callq *0x306224(%rip) ; (void *)0x0000000102b08000: objc_msgSend
0x102db5fcc <+620>: movzbl (%rax), %eax
0x102db5fcf <+623>: cmpl $0x44, %eax
0x102db5fd2 <+626>: jne 0x102db6009 ; <+681>
0x102db5fd4 <+628>: fldt (%r15)
0x102db5fd7 <+631>: jmp 0x102db6009 ; <+681>
0x102db5fd9 <+633>: movq %rax, %rbx
0x102db5fdc <+636>: movq %rbx, %rdi
0x102db5fdf <+639>: callq 0x102e60560 ; getAtomTarget
0x102db5fe4 <+644>: movq %rax, %r12
0x102db5fe7 <+647>: movq %r12, (%r15,%r14)
0x102db5feb <+651>: movl $0x400, %ecx
0x102db5ff0 <+656>: xorl %r8d, %r8d
0x102db5ff3 <+659>: movq %r13, %rdi
0x102db5ff6 <+662>: movq %r15, %rsi
0x102db5ff9 <+665>: movq %r15, %rdx
0x102db5ffc <+668>: callq 0x102d4ed60 ; __invoking___
0x102db6001 <+673>: cmpq %r12, (%r15)
0x102db6004 <+676>: jne 0x102db6009 ; <+681>
0x102db6006 <+678>: movq %rbx, (%r15)
0x102db6009 <+681>: movq %r15, %rax
0x102db600c <+684>: addq $0x18, %rsp
0x102db6010 <+688>: popq %rbx
0x102db6011 <+689>: popq %r12
0x102db6013 <+691>: popq %r13
0x102db6015 <+693>: popq %r14
0x102db6017 <+695>: popq %r15
0x102db6019 <+697>: popq %rbp
0x102db601a <+698>: retq
0x102db601b <+699>: leaq 0x35638e(%rip), %rax ; __CFOASafe
0x102db6022 <+706>: cmpb $0x0, (%rax)
0x102db6025 <+709>: je 0x102db603b ; <+731>
0x102db6027 <+711>: movl $0x15, %edi
0x102db602c <+716>: xorl %edx, %edx
0x102db602e <+718>: xorl %ecx, %ecx
0x102db6030 <+720>: xorl %r8d, %r8d
0x102db6033 <+723>: movq %r13, %rsi
0x102db6036 <+726>: callq 0x102e30880 ; __CFRecordAllocationEvent
0x102db603b <+731>: addq $0xa, %rbx
0x102db603f <+735>: movq -0x30(%rbp), %rdi
0x102db6043 <+739>: callq 0x102eaff76 ; symbol stub for: sel_getName
0x102db6048 <+744>: movq %rax, %rcx
0x102db604b <+747>: leaq 0x32c90e(%rip), %rdx ; #"*** -[%s %s]: message sent to deallocated instance %p"
0x102db6052 <+754>: movl $0x3, %edi
0x102db6057 <+759>: xorl %eax, %eax
0x102db6059 <+761>: movq %rdx, %rsi
0x102db605c <+764>: movq %rbx, %rdx
0x102db605f <+767>: movq %r13, %r8
0x102db6062 <+770>: callq 0x102dfd000 ; CFLog
0x102db6067 <+775>: int3
-> 0x102db6068 <+776>: jmp 0x102db6167 ; <+1031>
0x102db606d <+781>: movq %r12, %rdi
Try this
self.view = [[UIView alloc]initWithFrame:self.view.frame];
when changed viewController..
After read many discussion in stackoverflow, finally get one helpful advice, and that really work. 'Don't push two viewControllers animated at the same time. Push the first one without animation and push the second one with animation. UINavigationController can't handle two animations at the same time'
UINavigationController crash because of pushing and poping UIViewControllers
Finally, only change one line code: self.navigationController?.pushViewController(), set the animation as true. this bug is fixed. I Cannot believe this is iOS bug, or some unknown knowledge.

Resources