snapshot of memory for process on mac? - macos

I want to take a snapshot of memory of process in action on mac. I have no idea how to do it.
I have IDA-PRO for mac with me. Can it be used? How?
Can anyone suggest me a way to do this? (some documentation or example).
May be some techniques from uni can be used but I am also not aware of that.
I dont want to kill the process as I want to see whats changing after execution of instructions/commands.

You can send a signal to a running process to dump core into a file, which can be used with gdb later for postmortem analysis.
kill -ABRT <process-id>
It seems that you must configure your system to enable core dump. See http://developer.apple.com/library/mac/#technotes/tn2124/_index.html for details.
UPDATE:
Well, above link introduces a third party implementation of gcore, a command line tool to make a core dump of running processes:
http://www.osxbook.com/book/bonus/chapter8/core/
You may just want to grab the source and try:
http://www.osxbook.com/book/bonus/chapter8/core/download/gcore-1.3.tar.gz
To make a single FAT binary to use with ppc/i386/x86_64, just modify following lines from Makefile:
gcore: gcore.c
gcc -O2 -arch ppc -arch i386 -Wall -o $# $<
as:
gcore: gcore.c
gcc -O2 -arch ppc -arch i386 -arch x86_64 -Wall -o $# $<

Related

Specifying both -O2 and -O3 at same time

Some programs already uses -O2 flag, if I use -O3 flag, the program compiles with both -O2 and -O3 as shown by the task manager or by /proc/PID/cmdline.
For example, I'm using a Linux kernel built with Clang and full LTO. Even though I have these lines in the dkms configuration:
# /etc/dkms/framework.conf
export LLVM=1
export CC=clang
export CFLAGS="-O3 -march=native"
Now DKMS modules compile with both -O2 and -O3 flags. In this case, which flag is actually used?
For gcc, see https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Optimize-Options.html#Optimize-Options
If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.
clang doesn't document its option syntax as extensively, but it generally tries to be compatible with gcc, so it should be the same in this regard.

How to compile kernel with debug symbols for my own OS?

Hi I'm a beginner and trying to write a Linux like kernel.
I use Qemu as my emulator and currently debug in a assembly level.
However, by previous experience, I can debug Linux kernel with Qemu at source code (.c files) level.
So I would like to ask if I can do it with my own kernel, so that I can debug it with efficiency.
In order to provide more info, the following is my compilation script:
# Complie head.S
gcc -E ./PysicCodes/head.S > head.s
as --64 -o head.o head.s
gcc -E ./PysicCodes/AP_Boot.S > AP_Boot.s
as --64 -o AP_Boot.o AP_Boot.s
# Compile main program
gcc -mcmodel=large -fno-builtin -fno-stack-protector -m64 -c ./PysicCodes/*.c
# Interrupt hander requires general register only(since no XMM,SEE registers are saved)
gcc -mcmodel=large -fno-builtin -fno-stack-protector -m64 -mgeneral-regs-only -c ./PysicCodes/g_reg_only/*.c
# Linkage: Must put head.o at first, so that kernel start at head.o
ld -b elf64-x86-64 -z muldefs -o system head.o 8529A.o ACPI.o AP_Boot.o APIC.o cpu.o INT.o keyboard.o main.o Mem.o PCI.o Printk.o SMP.o Task.o Time.o TSS.o fat32.o -T ./PysicCodes/Kernel.lds
# Dump kernel
objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary system Kernel.bin
Thanks for anyone who would spend time on helping. Any extra information needed, please comment.
Currently I tried to add -ggdb3 as the compiling and linking options.
Furthermore, using the compiled object as the option for gdb
It simply worked.
In addition, adding "miDebuggerServerAddress": "localhost:1234" into Vscode's "launch.json" file, it actually can connect to Qemu and debug c code in vscode.
However only 1 problem, that vscode will run Qemu at start, so I have to press pause button as soon as I can after start debugger, and using "-exec" to put a hardware break-point.
There is an issue on git and currently haven't see an answer.

How to build a project without make (bare shell script)?

I heard that back in the old days (or maybe not so old), before the make utility was included in Unix, people used to write shell script to "make" and "install" their software.
Consider a project with: 2 source files main.c and util.c, a header util.h that uses the OpenGL library and needs to run on Ubuntu.
(Ubuntu and OpenGL are used just for the sake of being specific)
What would such a script actually need to do? Where can I find an example?
It's hard to imagine why anyone would want to revisit "the bad old days" before make, but it's actually not too difficult for a simple project. So given your particular example, a shell script to compile might look like this:
gcc -Wall -c main.c -o main.o -lglut -lglm
gcc -Wall -c util.c -o util.o -lglut -lglm
gcc -Wall main.o util.o -o main -lglut -lglm
What it does is to simply run through the entire "recipe" to build the project every time. The advantage is that, if the source code is all correct, it should result in an executable. The considerable disadvantages are that
if any step fails, so will subsequent steps that rely on the failed step
everything is rebuilt every time, wasting a lot of time
compile and link flags are all embedded into the script and hard to change
this approach has little hope of cross-platform compatibility
One can tinker with the basic shell script to improve on various aspects of this. Then, when that proves inadequate, one could write a program to do these things better. At that point, in essence, you will have re-invented make.

gccfilter and gcc 4.7.2 does not work, stops compiling

I have successfully installed the gccfilter (http://www.mixtion.org/gccfilter/) in my toolchain. The filter should actually work because all perl modules and other stuff has been installed the problem is that it does not work properly when I use for example the following command line:
gccfilter -c -a g++ -std=c++11 -O3 -DNDEBUG -I/"tonnes of includes" -o CMakeFiles/...../main.cpp.o
-c /...path.../App/main.cpp
.../variant.hpp:17:0,
from .../SceneParser.hpp:12,
from .../SimulationManager.hpp:12,
from .../main.cpp:8:
_ <-- Cursor is here
It compiles but after the error message it stops doing anything, the cursor is on the bottom line and nothing happens?
So the tool does not quite work, I am using gcc 4.7.2. i am not quite sure where the problem might be?

Mixed language C++, C and Fortran compilation with Cmake

Using g++, gcc and gfortran on GNU/Linux, I've written a simple script to compile and link together a number of source code files written in C++, C and Fortran. Here are the complete contents of the script. This script has been tested, and works well.
g++ -c test-Q.cpp -I./boost/boost_1_52_0/ -g
gcc -c paul2.c -g
gcc -c paul2_L1.c -g
gcc -c paul6.c -g
gcc -c paul6_L1.c -g
gcc -c fit_slope.c -g
gfortran -c getqpf.F -g
g++ -o test-Q test-Q.o paul2.o paul2_L1.o paul6.o paul6_L1.o fit_slope.o getqpf.o -g -lgfortran
To make this more cross-platform, I would like to re-write the script using Cmake. How might I handle mixed-language compilation?
The following test script listed below does not work, and will only selectively compile some of the files.
Is there perhaps another cross-platform build process that might be better suited for this type of compilation?
cmake_minimum_required (VERSION 2.6)
project (q-test)
include_directories(/media/RESEARCH/SAS2-version2/test-Q/boost/boost_1_52_0)
add_executable( q-test
test-Q.cpp
paul2.c
paul2_L1.c
paul6.c
paul6_L1.c
fit_slope.c
getqpf.F
) # end
You need to enable Fortran for the project like this:
project (q-test C CXX Fortran)
Also, you might want to use find_package(Boost) instead of hard coding an include path.

Resources