Thread: What am I overlooking with my library?

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,617
    > qsort( maps->buff, maps->size, sizeof(struct paw_map), paw_compare_maps );
    Your size should be the number of elements, not the number of bytes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #17
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Never mind, I misunderstood the 2nd parameter of qsort(), thought it was total size but was just the count of elements

  3. #18
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Quote Originally Posted by Salem View Post
    > qsort( maps->buff, maps->size, sizeof(struct paw_map), paw_compare_maps );
    Your size should be the number of elements, not the number of bytes.
    I shoulda reloaded the page 1st huh? Whoopsie

  4. #19
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Trying to add support for register grabbing in paw but currently get a compiler error even after referencing a guide, the compiler error is that it cannot find <machine/reg.h> which is needed for the structs expeceted by PT_GETREGS etc, anyone know what package I should install on my manjaro distro to fix this?

    Edit: btw, for anyone interested, I was referencing this guide: How Debuggers Work: Getting and Setting x86 Registers, Part 1 | Moritz Systems

  5. #20
    Registered User
    Join Date
    May 2009
    Posts
    4,005
    3 minutes of searching implies "machine/reg.h" is BSD based header; and it is likely a different header under Linux.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #21
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Quote Originally Posted by stahta01 View Post
    3 minutes of searching implies "machine/reg.h" is BSD based header; and it is likely a different header under Linux.

    Tim S.
    Well that's more than I got, kept getting directed to sys/reg.h (which I'm currently attempting to use but is not going well).

    Side question, anyone see why this would skip the loop?
    Code:
    #if defined( __x86_64__ ) && defined( LLONG_MAX ) && LLONG_MAX > LONG_MAX
    typedef unsigned long long pawt_reg;
    #define PRI_PAWT "ll"
    #else
    typedef unsigned long pawt_reg;
    #define PRI_PAWT "l"
    #endif
    
    #define PAW_MAX_REGISTERS 64
    
    struct paw_gpreg
    {
    	pawt_reg regs[PAW_MAX_REGISTERS];
    };
    
    struct paw_fpreg
    {
    	pawt_reg regs[PAW_MAX_REGISTERS];
    };
    
    struct paw_dbreg
    {
    	pawt_reg regs[PAW_MAX_REGISTERS];
    };
    ...
    	puts("Getting General Purpose Registers");
    	gpr = paw_get_app_gpr( app );
    	
    	for ( size_t i = 0; i < PAW_MAX_REGISTERS; ++i )
    	{
    		printf("Register %zu = %016" PRI_PAWT "X\n", i, gpr.regs[i] );
    	}
    	puts("Success, exiting...");
    The related functions:
    Code:
    PAW_SHARED struct paw_gpreg paw_get_app_gpr( struct paw_app *app )
    {
    	struct paw_gpreg gpr;
    	memset( &gpr, 0, sizeof(struct paw_dbreg) );
    	(void)ptrace( PT_GETREGS, app->pid, &gpr, 0 );
    	return gpr;
    }
    
    PAW_SHARED struct paw_fpreg paw_get_app_fpr( struct paw_app *app )
    {
    	struct paw_fpreg fpr;
    	memset( &fpr, 0, sizeof(struct paw_fpreg) );
    	(void)ptrace( PT_GETREGS, app->pid, &fpr, 0 );
    	return fpr;
    }
    
    PAW_SHARED struct paw_dbreg paw_get_app_dbr( struct paw_app *app )
    {
    	struct paw_dbreg dbr;
    	memset( &dbr, 0, sizeof(struct paw_dbreg) );
    #ifdef PT_GETDBREGS
    	(void)ptrace( PT_GETDBREGS, app->pid, &dbr, 0 );
    #endif
    	return dbr;
    }
    ??? Soon as I fixed the mistake in the paw_get_app_fpr() function that I noticed after this post the loop decided to execute, I can only assume make decide the file hadn't been updated the first time

  7. #22
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Started writing the lua wrapper for paw and ran into a problem with library locations, here's what I have right now:
    Code:
    include dir.mak
    include $(MAK_DIR)/sys/sys.mak
    include $(MAK_DIR)/cc/cc.mak
    
    ALL_SRC_FILES:=$(wildcard $(SRC_DIR)/*.c)
    
    lpaw_src_files:=$(filter-out lchkpaw.c,$(ALL_SRC_FILES))
    
    lpaw_obj_files:=$(lpaw_src_files:%=%.obj)
    lpaw_o_files:=$(lpaw_src_files:%=%.o)
    liblpaw_so:=liblpaw$(SYS_LIB_SFX)
    
    lpawd_obj_files:=$(lpaw_src_files:%=%d.obj)
    lpawd_o_files:=$(lpaw_src_files:%=%d.o)
    liblpawd_so:=liblpawd$(SYS_LIB_SFX)
    
    lchkpaw_out:=lchkpaw$(SYS_EXE_SFX)
    lchkpawd_out:=lchkpawd$(SYS_EXE_SFX)
    
    IFLAGS:=$(CC_I) $(INC_DIR) $(CC_I) $(PAW_DIR)/include
    LFLAGS:=$(CC_L) $(LIB_DIR) $(CC_L) $(PAW_DIR)/lib
    BFLAGS:=-fPIC $(IFLAGS) $(LFLAGS)
    CFLAGS:=-fPIC $(IFLAGS) $(LFLAGS)
    
    LD_WIN32_PATHS:=PATH="$(BIN_DIR);$(PATH)"
    LD_POSIX_PATHS:=LD_LIBRARY_PATH=$(BIN_DIR):$(LD_LIBRARY_PATHS)
    LD_PATHS:=$(if $(SYS_IS_WINDOWS),$(LD_WIN32_PATHS),$(LD_POSIX_PATHS))
    $(info LD_PATHS=$(LD_PATHS))
    
    # TODO: create a macro for the target debugger option
    DBG_FLAGS:=-ggdb $(CC_D) _DEBUG
    
    run: build $(BIN_DIR)/$(liblpaw_so)
    	$(LD_PATHS) && $(BIN_DIR)/$(lchkpaw_out)
    
    rebuild: clean build
    
    debug: build_debug $(BIN_DIR)/$(liblpawd_so)
    	$(LD_PATHS) && cd $(BIN_DIR) && gdb --args ./$(lchkpaw_out)
    
    gede: build_debug
    	$(LD_PATHS) && cd $(BIN_DIR) &&
    
    rebuild_debug: clean build_debug
    
    clean:
    	$(SYS_DEL) *.exe
    	$(SYS_DEL) *.dll
    	$(SYS_DEL) *.obj
    	$(SYS_DEL) *.out
    	$(SYS_DEL) *.so
    	$(SYS_DEL) *.o
    
    # Quick
    
    build: $(BIN_DIR)/$(lchkpaw_out)
    
    build_lib: $(LIB_DIR)/$(liblpaw_so)
    
    $(BIN_DIR)/lchkpaw.exe: $(LIB_DIR)/liblpaw.dll
    	$(LD_PATHS) && $(CC) $(BFLAGS) $(CC_o) $@ $(SRC_DIR)/lchkpaw.c $(CC_l)lpaw $(CC_l)lua
    
    $(LIB_DIR)/liblpaw32.dll: $(lpaw_obj_files) $(LIB_DIR)/libpaw32.dll
    	$(LD_PATHS) && $(CC) $(BFLAGS) $(CC_o) $@ $(lpaw_obj_files) $(CC_l)paw $(CC_l)lua
    
    $(BIN_DIR)/lchkpaw: $(LIB_DIR)/liblpaw.so
    	$(LD_PATHS) && $(CC) $(BFLAGS) $(CC_o) $@ $(SRC_DIR)/lchkpaw.c $(CC_l)lpaw $(CC_l)lua
    
    $(LIB_DIR)/liblpaw.so: $(lpaw_o_files) $(LIB_DIR)/libpaw.so
    	$(LD_PATHS) && $(CC) $(BFLAGS) $(CC_o) $@ $(lpaw_o_files) $(CC_l)paw $(CC_l)lua
    
    $(SRC_DIR)/%.obj: $(SRC_DIR)/%
    	$(CC) $(CFLAGS) $(CC_o) $@ $(CC_c) $<
    	
    $(SRC_DIR)/%.o: $(SRC_DIR)/%
    	$(CC) $(CFLAGS) $(CC_o) $@ $(CC_c) $<
    
    # Debug
    	
    build_debug: $(BIN_DIR)/$(lchkpawd_out)
    
    build_debug_lib: $(LIB_DIR)/$(liblpawd_so)
    
    $(BIN_DIR)/lchkpawd.exe: $(LIB_DIR)/liblpawd.dll
    	$(LD_PATHS) && $(CC) $(DBG_FLAGS) $(BFLAGS) $(CC_o) $@ $(SRC_DIR)/lchkpaw.c $(CC_l)lpawd $(CC_l)lua
    
    $(LIB_DIR)/liblpaw32d.dll: $(lpawd_obj_files) $(LIB_DIR)/libpawd32.dll
    	$(LD_PATHS) && $(CC) $(DBG_FLAGS) $(BFLAGS) $(CC_o) $@ $(lpawd_obj_files) $(CC_l)pawd $(CC_l)lua
    
    $(BIN_DIR)/lchkpawd: $(LIB_DIR)/liblpawd.so
    	$(LD_PATHS) && $(CC) $(DBG_FLAGS) $(BFLAGS) $(CC_o) $@ $(SRC_DIR)/lchkpaw.c $(CC_l)lpawd $(CC_l)lua
    
    $(LIB_DIR)/liblpawd.so: $(lpawd_o_files) $(LIB_DIR)/libpawd.so
    	$(LD_PATHS) && $(CC) $(DBG_FLAGS) $(BFLAGS) $(CC_o) $@ $(lpawd_o_files) $(CC_l)pawd $(CC_l)lua
    
    $(SRC_DIR)/%d.obj: $(SRC_DIR)/%
    	$(LD_PATHS) && $(CC) $(DBG_FLAGS) $(CFLAGS) $(CC_o) $@ $(CC_c) $<
    	
    $(SRC_DIR)/%d.o: $(SRC_DIR)/%
    	$(CC) $(DBG_FLAGS) $(CFLAGS) $(CC_o) $@ $(CC_c) $<
    
    # Common
    
    $(BIN_DIR)/%.dll: $(LIB_DIR)/%.dll
    	cp $< $@
    
    $(BIN_DIR)/%.so: $(LIB_DIR)/%.so
    	cp $< $@
    	
    $(LIB_DIR)/libpaw%: $(PAW_DIR)/lib/libpaw%
    	cp $< $@
    
    $(PAW_DIR)/lib/%: %
    	cd $(PAW_DIR) && $(MAKE) $<
    
    %.mak:
    
    .PHONY: rebuild rebuild_debug clean build build_lib build_debug build_debug_lib
    And the exact output is this:
    Code:
    make --no-print-directory build
    make -f main.mak build
    LD_PATHS=LD_LIBRARY_PATH=./bin:
    LD_LIBRARY_PATH=./bin: && gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o bin/lchkpaw ./src/lchkpaw.c -llpaw -llua
    /usr/bin/ld: warning: libpaw.so, needed by ./lib/liblpaw.so, not found (try using -rpath or -rpath-link)
    /usr/bin/ld: ./lib/liblpaw.so: undefined reference to `paw_init'
    collect2: error: ld returned 1 exit status
    make[1]: *** [main.mak:67: bin/lchkpaw] Error 1
    make: *** [GNUmakefile:5: build] Error 2
    Compilation failed.
    I don't see what I'm overlooking, any else able to spot it?

    Edit: I did check the folders and the ./lib ones were correctly generated but the ./bin ones I had to manually copy, didn't change the message though

  8. #23
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    I think I solved the previous issue but to confirm I need to get passed one that popped up now:
    Code:
    ...
    gcc -I ./include -L ./lib  -fPIC -shared -o lib/libpaw.so src/app.c.o src/apps.c.o src/lib.c.o src/libs.c.o src/maps.c.o src/paw.c.o src/shared.c.o -ldl
    cp ../paw/lib/libpaw.so lib/libpaw.so
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o lib/liblpaw.so ./src/lapp.c.o ./src/lapps.c.o ./src/lchkpaw.c.o ./src/llib.c.o ./src/llibs.c.o ./src/lmaps.c.o ./src/lpaw.c.o -lpaw -llua -Wl,rpath=.
    /usr/bin/ld: cannot find rpath=.: No such file or directory
    collect2: error: ld returned 1 exit status
    make[1]: *** [main.mak:79: lib/liblpaw.so] Error 1
    make: *** [GNUmakefile:5: rebuild] Error 2
    Compilation failed.
    How can '.' not be a valid directory? Or am I missing something here?
    Full output:
    Code:
    make --no-print-directory rebuild
    make -f main.mak rebuild
    LPATHS==.
    rm -f ./bin/*.exe
    rm -f ./bin/*.dll
    rm -f ./lib/*.dll
    rm -f ./src/*.obj
    rm -f ./bin/*.out
    rm -f ./bin/*.so
    rm -f ./lib/*.so
    rm -f ./src/*.o
    cd ../paw && make clean
    git -C ../mak pull
    Already up to date.
    make -f main.mak clean
    rm -f ./bin/*.exe
    rm -f ./lib/*.dll
    rm -f ./src/*.obj
    rm -f ./bin/*.out
    rm -f ./lib/*.so
    rm -f ./src/*.o
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lapp.c.o -c src/lapp.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lapps.c.o -c src/lapps.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lchkpaw.c.o -c src/lchkpaw.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/llib.c.o -c src/llib.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/llibs.c.o -c src/llibs.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lmaps.c.o -c src/lmaps.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lpaw.c.o -c src/lpaw.c
    cd ../paw && make ./lib/libpaw.so
    git -C ../mak pull
    Already up to date.
    make -f main.mak lib/libpaw.so
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/app.c.o -c src/app.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/apps.c.o -c src/apps.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/lib.c.o -c src/lib.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/libs.c.o -c src/libs.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/maps.c.o -c src/maps.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/paw.c.o -c src/paw.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/shared.c.o -c src/shared.c
    gcc -I ./include -L ./lib  -fPIC -shared -o lib/libpaw.so src/app.c.o src/apps.c.o src/lib.c.o src/libs.c.o src/maps.c.o src/paw.c.o src/shared.c.o -ldl
    cp ../paw/lib/libpaw.so lib/libpaw.so
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o lib/liblpaw.so ./src/lapp.c.o ./src/lapps.c.o ./src/lchkpaw.c.o ./src/llib.c.o ./src/llibs.c.o ./src/lmaps.c.o ./src/lpaw.c.o -lpaw -llua -Wl,rpath=.
    /usr/bin/ld: cannot find rpath=.: No such file or directory
    collect2: error: ld returned 1 exit status
    make[1]: *** [main.mak:79: lib/liblpaw.so] Error 1
    make: *** [GNUmakefile:5: rebuild] Error 2
    Compilation failed.

  9. #24
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    I think I solved the previous issue but to confirm I need to get passed one that popped up now:
    Code:
    ...
    gcc -I ./include -L ./lib  -fPIC -shared -o lib/libpaw.so src/app.c.o src/apps.c.o src/lib.c.o src/libs.c.o src/maps.c.o src/paw.c.o src/shared.c.o -ldl
    cp ../paw/lib/libpaw.so lib/libpaw.so
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o lib/liblpaw.so ./src/lapp.c.o ./src/lapps.c.o ./src/lchkpaw.c.o ./src/llib.c.o ./src/llibs.c.o ./src/lmaps.c.o ./src/lpaw.c.o -lpaw -llua -Wl,rpath=.
    /usr/bin/ld: cannot find rpath=.: No such file or directory
    collect2: error: ld returned 1 exit status
    make[1]: *** [main.mak:79: lib/liblpaw.so] Error 1
    make: *** [GNUmakefile:5: rebuild] Error 2
    Compilation failed.
    How can '.' not be a valid directory? Or am I missing something here?
    Full output:
    Code:
    make --no-print-directory rebuild
    make -f main.mak rebuild
    LPATHS==.
    rm -f ./bin/*.exe
    rm -f ./bin/*.dll
    rm -f ./lib/*.dll
    rm -f ./src/*.obj
    rm -f ./bin/*.out
    rm -f ./bin/*.so
    rm -f ./lib/*.so
    rm -f ./src/*.o
    cd ../paw && make clean
    git -C ../mak pull
    Already up to date.
    make -f main.mak clean
    rm -f ./bin/*.exe
    rm -f ./lib/*.dll
    rm -f ./src/*.obj
    rm -f ./bin/*.out
    rm -f ./lib/*.so
    rm -f ./src/*.o
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lapp.c.o -c src/lapp.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lapps.c.o -c src/lapps.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lchkpaw.c.o -c src/lchkpaw.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/llib.c.o -c src/llib.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/llibs.c.o -c src/llibs.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lmaps.c.o -c src/lmaps.c
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o src/lpaw.c.o -c src/lpaw.c
    cd ../paw && make ./lib/libpaw.so
    git -C ../mak pull
    Already up to date.
    make -f main.mak lib/libpaw.so
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/app.c.o -c src/app.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/apps.c.o -c src/apps.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/lib.c.o -c src/lib.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/libs.c.o -c src/libs.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/maps.c.o -c src/maps.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/paw.c.o -c src/paw.c
    gcc -I ./include -L ./lib  -fPIC -D PAW_BUILD_SHARED -o src/shared.c.o -c src/shared.c
    gcc -I ./include -L ./lib  -fPIC -shared -o lib/libpaw.so src/app.c.o src/apps.c.o src/lib.c.o src/libs.c.o src/maps.c.o src/paw.c.o src/shared.c.o -ldl
    cp ../paw/lib/libpaw.so lib/libpaw.so
    gcc -fPIC -I ./include -I ../paw/include -L ./lib -L ../paw/lib -o lib/liblpaw.so ./src/lapp.c.o ./src/lapps.c.o ./src/lchkpaw.c.o ./src/llib.c.o ./src/llibs.c.o ./src/lmaps.c.o ./src/lpaw.c.o -lpaw -llua -Wl,rpath=.
    /usr/bin/ld: cannot find rpath=.: No such file or directory
    collect2: error: ld returned 1 exit status
    make[1]: *** [main.mak:79: lib/liblpaw.so] Error 1
    make: *** [GNUmakefile:5: rebuild] Error 2
    Compilation failed.
    Edit: Never mind, just realised I missed the '-' character in front of rpath

  10. #25
    Registered User
    Join Date
    Apr 2021
    Posts
    33
    Try using "-Wl,-rpath" (note: -r) instead of "-Wl,rpath"

  11. #26
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Finally managed to fix the issue by setting rpath to $(LIB_DIR) instead of .

  12. #27
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,249
    Quote Originally Posted by aghast View Post
    Try using "-Wl,-rpath" (note: -r) instead of "-Wl,rpath"
    I'm late to see this but yeah I noticed that sometime between my post and actually fixing the issue, after that I got sidetracked with fixing the issue with initializing liblpaw via lua

    Edit: Thx anyways btw

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overlooking Something in an Array
    By Feralix in forum C Programming
    Replies: 8
    Last Post: 07-09-2016, 01:37 AM
  2. Replies: 8
    Last Post: 12-10-2014, 03:00 PM
  3. Overlooking something in a comparison
    By csharp100 in forum C Programming
    Replies: 7
    Last Post: 04-29-2012, 09:21 PM
  4. probably something simple I'm overlooking
    By tomasc in forum C++ Programming
    Replies: 3
    Last Post: 05-19-2008, 11:07 PM
  5. Replies: 19
    Last Post: 01-12-2006, 11:04 AM

Tags for this Thread