Is there a way to programmatically detect/determine if a binary (separate from my application) has been compiled i386, x86_x64, or both? I imagine there is a way (obviously), although I really have no idea how. Any suggestions or advice would be appreciated, thank you.
EDIT: I found an example on the Apple developer website, although it's written in C and setup to be used more as a command line tool. If anyone would know how to implement it into my objective-c code that would be extremely helpful.
Example [C] code: CheckExecutableArchitecture
You can include the mach-o headers and simply load the binary and then check the mach_header. You should read the Mach-O format description from Apple for more info, it includes everything you need: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html
- (void)checkArchitecture {
NSArray *bundleArch = [[NSBundle bundleWithPath:#"/path/to/other/bundle"] executableArchitectures];
}
Related
Is there a way how to check source code files (Objective C) and show warning for methods/functions that are longer than x lines (where the x can be configured). Something that can be integrated in Xcode would be great.
I have looked into these two following static analyzers for C/C++/ObjC code if they provide such functionality but I couldn't find anything mentioned in the documentation:
http://clang-analyzer.llvm.org
http://oclint.org (longMethod rule)
Any ideas where to look further?
Hmmm, looks like you could write an Xcode plugin to do that, sounds like it could be useful! I'll admit to not having done one before but I did find this link as a starting point.
Is there a way to do a Spotlight query, in Obj-C, similar to what mdfind does? I need to write a method with the following signature:
-(NSString *)mdfind:(NSString *)theFileToLookFor
where the returned NSString is the first path found by the search.
Any help will be really appreciated.
NSMetadataQuery is the wrapper around the Carbon-level MDQuery API, which is how one interacts with the user's spotlight database.
the apis are in CoreServices.framework. start with the ones which have the prefix MDQuery
I know this is pretty much a stupid question. I know almost nothing about how compiler really works.
But recently I want find what symbol name does the compiler generate for my ivar, my methods.
Where and how can I know the answer? (I have only used some IDEs. So if the solution is better to be simple . And it would be great help if the instructions you provide is really explicit)
(By the way,is there any reference that i can learn about the things like this?)
PS.I'm IOS developer.And if gcc and LLVM works different answer on this question , I would like to know both.
You can use nm to dump the content of a binary object. Then, each compiler has its own way of mangling. I suggest you have a look at Name mangling for objective C in wikipedia, it will help you understand how mangling works.
Surely GCC and Clang must have compatible name-mangling schemes, since they can use each other's code.
If you are using XCode 3 select a source file and then pick "Show Assembly Code" from the Build menu.
Apparently XCode 4 users do not need assembly code :-(
Out of curiosity, what may the rationale behind these function names (found in Apple's Quartz Core framework) be?
ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv()
ZNK2CA6Render9Animation9next_timeEdRd()
ZN2CA11GenericRectIiE5insetEii()
Do you think the developers somehow encoded argument types in function names? How do you find yourself putting "EP19" in there in the course of day-to-day coding? In what circumstances do such barely readable function names actually help you read code and otherwise be more productive?
Thanks in advance for any hints, and Merry Christmas!
These 'mangled' names are automatically generated by the C++ compiler and indeed encode type information.
Sometimes I want to look up the implementations of functions in the stdlib, I've downloaded the sourcecode, but it's quite messy.
Just greping is not really suitable because of the many hits.
Does anyone know a webpage doxygen style that has the documentation.
The same goes for the linux kernel.
Thanks
You should check if your distribution is using the vanilla GLIBC or the EGLIBC fork (Debian and Ubuntu have switched to EGLIBC EDIT: they switched back around 2014).
Anyway, the repository browser for GLIBC is at http://sourceware.org/git/?p=glibc.git
http://code.woboq.org/userspace/glibc/, posted by #guruz below, is a good alternative.
The source is a bit complicated by the presence of multiple versions of the same files.
How about this for libc documentation? And perhaps this for the kernel? There is also Google Code search; here is an example search.
More on Google Code Search You can enter search queries like this: package:linux-2.6 malloc for any references to malloc in the linux-2.6 kernel.
Edit: Google Code search is now shut down. But you can access the git repo at http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git and it has search as well.
You can try http://code.woboq.org/userspace/glibc/
It has nice navigation/hilighting similar to an IDE.
To help navigate the source to glibc, perhaps try something like ctags or cscope?
Note: I get dumber every time I look at the glibc source, so please be careful! :)
If you are using GNU C (glibc), the functions (beyond the GNU extensions) follow the POSIX standard as far as their arguments, implementation, failure and return values. If you want to peek under the hood of static members, you'll have to look at the code.
Every push (that I can remember) to try and adopt something like Doxygen for glibc was rejected for the following reasons:
Redundant, POSIX already documents almost everything thats exposed, as well as man and info pages.
Too much work initially
More work for maintainers
As far as the kernel goes, Linux does use a system very similar to Doxygen called Kerneldoc.
You can also get actual Doxygen-generated docs from http://fossies.org/dox/glibc.