How to view XCode( assembly code equivalent) at the break point?
I have gone to Thread1 and it shows objective-c for the [ViewController viewDidLoad] and then assembly for [UIViewController view] and [UIWindow makeKeyAndVisible]. I want to be able to see the assembly for [ViewController viewDidLoad] with the marker at the break pt?
(Product->GenerateOutput->Generate Assembly File: doesn't show the break pts.)
thx
void addme(int *a)
{
*a += 0xFF;// <-- I want to see the assembly for this: should see an instruction "ADD" in the assembly break down
*a += 1;
*a += 2;
}
- (void)viewDidLoad
{
[super viewDidLoad];
int a = 12;
addme(&a);
}
Steps:
Put breakpoint where you want to see the assembly code
Run program
Once program pauses hit the button that looks like ->| (but pointing down)
Repeat step 3 a lot
Dance
See the world
Wonder at the joys of life
Pop bottles
Grow old
Die
I'm not quite sure this is what you're asking for, but I just did it (well, steps 1-5 & 8) and it worked for me.
It's at the bottom of the screen, above the console.
And it's also likely that you won't see an assembly ADD instruction at all, since compile time constants are calculated and thus optimized away by the compiler at compile time.
#jdl At the matter of fact i don't know Objective-C and #Dustin doesn't know asm... As i understood viewDidLoad function will execute a code in it when some object is loaded. In my opinion you can compile only that part of code which you included in your question and look into assembly code via IDA pro for Mac OS or some other debugger.
Related
I'll try to keep it short. I want to create a 3D FPS game, just for myself, that can run on multiple platforms, but I figured that to keep it simple, perhaps it is best to start off with something that is exclusively for macOS. I opted for Objective-C because
(a) Window Application projects in Xcode can only be coded either in Obj-C or Swift (since we are dealing with Cocoa API) and
(b) Obj-C is closer to old-school then Swift.
But before I learn to draw/render 2D-shapes on the window's canvas by writing code, I have to learn to invoke an application window with its properties set to my liking. I've spent hours doing research and experimenting with chunks of code. This is what I've tried: I open with
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
Then I go with ...
1)
NSWindow *window = [[[NSApplication sharedApplication] windows] firstObject];
NSRect frame = [window frame];
frame.origin.x = 100;
frame.origin.y = 200;
frame.size.width = 100;
frame.size.height = 500;
[window setFrame: frame display: YES];
... and close with ...
NSApplicationMain(argc, argv); // runs the win display function.
}
return (0) ;
}
But no visible changes. Nothing really gets reset. So instead of (1) I tried ...
2)
NSWindow *window = [[[NSApplication sharedApplication] windows] firstObject];
NSPoint newOrigin;
newOrigin.x = 400;
newOrigin.y = 100;
[window setFrameOrigin : newOrigin];
Still nothing. Then instead of (2) I tried:
3)
NSWindowController* controller = [[NSWindowController alloc]
initWithWindowNibName:#"MainMenu"];
[controller showWindow:nil];
Great. Now it's spitting out something I don't understand, especially since I'm new to Obj-C:
2020-02-08 21:53:49.782197-0800
tryout_macApp2[14333:939233] [Nib Loading] Failed
to connect (delegate) outlet from
(NSWindowController) to (AppDelegate): missing
setter or instance variable
I remember dicing around with an ApplicationDelegate, with CGSizeMake(), etc., but it just made the experience really inundating and frustrating. Nothing happened. Then there are NSView, NSViewController, and other classes, which is really mindboggling and begs the question: why are there so many classes when all I want to do is override the preset origin of the window and the dimensions preset by the MainMenu.xib file? (By the way, this project is derived from a Window Application project provided by Xcode.)
I really can't think of anything else to add to give you the entire picture of my predicament, so if you feel that something is missing, please chime in.
[Edit:] Moving forward to phase 2 of my project here: How do I paint/draw/render a dot or color a pixel on the canvas of my window with only a few lines in Obj-C on Mac OS X using Xcode?.
The short answer is that main() is too early to be trying to do this. Instead, implement -applicationDidFinishLaunching: on your app delegate class, and do it there. Leave main() as it was originally created by Xcode's template.
After that, I would say to obtain the window (if there's only going to be one main one), it's better to add an outlet to your app delegate and then, in the NIB, connect that outlet to the window. Then, you can use that outlet whenever you want to refer to the window.
Also, make sure that Visible at Launch is disabled for the window in the NIB. That's so you configure it as you want before showing it.
For a more complex app, it's probably better to not put a window into the Main Menu NIB. Instead, make a separate NIB for the window. Then, load it using a window controller object and ask that for its window.
I love Objective-C but also feel your pain, it has this testy ability to frustrate you endlessly.
I have not really developed a game but let me try and point you in the right direction. I think you need a UIViewController.
Now each UIViewController has a built in UIView that sort of represents the visible portion of it. You can use this or add a UIView and use that, whichever depends on your implementation. For now I'd suggest add a separate UIView and use that rather. Once you're comfortable you can then move the implementation to the UIViewController's view if you need to.
Anyhow, for now, create a UIView subclass, say MyGame or something, as for now all your code will end up there.
To do all of the above is not easy, especially if its the first time. If you can follow some tutorial it will be great. Even if the tutorial just adds a button, you can use it and replace the button with your view.
Anyhow, now that you've got that running and the view you've added shows up in green or some other neon colour just to verify that you can indeed change its properties, you're good to go.
Now you start. In MyGame, implement the
-(void)drawRect:(CGRect)rect
message, grab the context through
UIGraphicsGetCurrentContext
and start drawing lines and stuff on it, basically the stuff I understand you are interested in doing. You can also, through the same context, change the origin of what you are doing.
Hope this helps.
I'm trying to import Agent Geometry Kit (https://github.com/hfossli/AGGeometryKit) which is written in Objective-C into a Swift project.
I start by copying all the source files into my project, then I create a bridge header file in which I import all the header files I just added (which looks like this https://gist.github.com/JeanCParis/97dc6c27c70a4f00dbb0)
My problem is that although all the imported classes and structs are now available in my project, unions like AGKQuad are not.
Am I doing something wrong, or are unions not usable in Swift and if so how can I best bypass this problem ? Many thanks in advance !
Jean-Christophe
EDIT : I'm still a neophyte in developing on IOS, but can't I just make a Objective-C class which I can call from my Swift project to "do the job" and send me the result I'm looking for ? I tried to do just that and it unfortunately does not give me the expected result, although it might be that I don't yet fully understanding how Agent Geometry Kit works (what the method does comes from the readme file on github)
#implementation DoTheJob
- (UIImageView*)DoDaJob:(UIImage*)image {
UIImageView *view = [[UIImageView alloc] initWithImage:image];
[view.layer ensureAnchorPointIsSetToZero]; // set the anchor point to [0, 0] (this method keeps the same position)
AGKQuad quad = view.layer.quadrilateral;
quad.br.x += 600; // shift bottom right x-value with 20 pixels
quad.br.y += 500; // shift bottom right y-value with 50 pixels
view.layer.quadrilateral = quad; // the quad is converted to CATransform3D and applied
printf("DoingDaJob");
return view;
}
#end
Should this work in principle ?
C unions are apparently not supported (yet).
The code I posted in my edited question works just fine, even though it might not be the optimal solution, I was simply misunderstanding how this library works.
I just started doing iPhone dev. At the moment I'm trying to fix a bug which exists in an already built app. The main function looks as follows:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
This seems pretty typical from what I understand; I'm guessing UIApplicationMain is the main loop, which the source files that have been created for the app specifically connects to via the use of delegates/function pointers in Objective-C (note, while I'm quite proficient in C++, I hardly know much about iOS or Objective-C).
So, what I'd like to know is how I can step through my source files and track down the calculation bug I'm experiencing for this app. Unfortunately, all I receive is disassembly when stepping into the UIApplicationMain, and while I know the very basics of asm and can interpret it (for the most part), I'd rather not unless I absolutely have to - especially considering the fact that the debugger appears to be outputting AT&T syntax (NOTE: if it's possible to change the asm syntax to Intel, I'd appreciate it if someone could state how to do that).
Thanks.
You can put breakpoints on every line by clicking on the gray space between the code and the project explorer on the left. When running, upon encountering a breakpoint the simulator or device will stop running and the code will show up. Then hit either the down arrow button that will show up on the upper left of the debugging window at the bottom to go line by line, which will show asm when appropriate, or hit the right-pointing arrow which will run until the next breakpoint is hit. You can disable breakpoints by deleting them individually or by toggling the breakpoints button at the top.
The main function in iOS is almost identical in all projects. It just serves to get the ball rolling. Here is a good tutorial for debugging especially crashes in Xcode. debugging tutorial
(Answer to NOTE not the actual question)
xcode can be set to use gdb (in scheme settings):
simply add to your .gdbinit
(which is located in your home dir ) :
"set disassembly-flavor intel"
for lldb there might be something similar
I am getting a crash the second time I attempt to add a certain view as a subview. The crash happens here:
-(void)AddAsScrollableSubContext:(UIView*)view {
[pExtendedScrollableSubContextBounds addSubview: view]; //CRASH HERE
pSubScroll.userInteractionEnabled = true;
}
the second time I call...
[mSongContext AddAsScrollableSubContext:pEQRoot];
The flow is something along the lines of
[mSongContext AddAsScrollableSubContext:pEQRoot];
...Load a lot of stuff
...Press a Button
...Unload a lot of stuff
[pEQRoot removeFromSuperview];
...Press a Button
[mSongContext AddAsScrollableSubContext:pEQRoot];
When I get the bad access the callstack looks like the following:
Both objects (pExtendedScrollableSubContextBounds and pEQRoot) appear to be valid. Adding other subview to pExtendedScrollableSubContextBounds works fine and calling other operations on pEQRoot (subview, frame) also work.
I read the in objsend r0 was the object and r1 was the selector so I looked at the memory address for r1 and saw...
This feels like I am trashing memory somewhere around isKindOfClass: but I am not quite sure. Could anyone point me to more info on iOS obj_msgsend? is there a way I can setup a watch point to catch when this memory trash is occurring?
Use NSZombies to fix the problem.
On a slightly unrelated note, there's a rule of thumb - NARC which stands for new, allocate, retain, copy. If a method call includes any of these keywords, then we have ownership of the object and we are then supposed to release the object.
Despite searching all over the place, I can't find the answer to my question. So let's see how good y'all are. :)
I'm working on an app that uses an NSPopover which is only available in 10.7 Lion but I want the app to compile for 10.5 and higher. I'm using a preprocessor directive to wrap the related popover code which seems to do the trick... However, the last piece I'm still getting errors on is the .zib in Interface Builder. How do I go about cleaning up the errors shown in the Issues Navigator stating "Class Unavailable: NSPopover on Mac OS X versions prior to 10.7"?
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#property (assign) IBOutlet NSPopover *popover;
}
#endif
#endif
The above works in xxx.h and xxx.m's, but how do I get around the .xib errors?
Despite the error (Red), it builds successfully. However am I wrong to expect the 10.7 features (popover) to work in 10.7 because they don't... What am I missing here?
You shouldn't use preprocessors for this but check for availability at runtime using NSClassFromString(). The preprocessor runs at compile time, thus it won't detect what system the app is being run on.
Create three nibs, one for each of 10.5, 10.6 and 10.7 and load the one you need (or do it in code), but pick which one at run time, not compile time, e.g.
MyVC *vc = nil;
if (NSClassFromString(#"NSPopover"))
{
vc = [NSViewController initWithNibName:#"MyVC-Lion" bundle:nil];
}
else if (/* check for 10.6+ only features */)
{
vc = [NSViewController initWithNibName:#"MyVC-SL" bundle:nil];
}
else
{
vc = [NSViewController initWithNibName:#"MyVC" bundle:nil];
}
// ...
Not a real answer to your question, apologies, but 2 possible workarounds: isn't it possible to create 2 versions of your xib, and depending on the target, compile on or the other? This would be a bit more work to maintain, but if your UI is pretty stable, this should be the easiest way.
Or you could add your "10.7 specific" UI component(s) programmatically instead of using the IB. If you just have one or a few popovers, it shouldn't be to difficult to do, and the proprocessor guards would work fine.