Hi,
I have written this simple FASM program... its a small window with a textbox, a vertical scrollbar and a button (which does nothing right now). Strange thing is that I get a segfault when I compile it with the commented gtk_init line :( Using 0 for both parameters work (but I cant access argc/argv then). Any idea why?
Used the wrong words. I get the segfault when I try to run the compiled programm...:
Makefile:
Linux.inc (Privalovs ccall.inc... just renamed it ;) )
I have written this simple FASM program... its a small window with a textbox, a vertical scrollbar and a button (which does nothing right now). Strange thing is that I get a segfault when I compile it with the commented gtk_init line :( Using 0 for both parameters work (but I cant access argc/argv then). Any idea why?
Used the wrong words. I get the segfault when I try to run the compiled programm...:
bazik@exodus fasmpad $ make
fasm fasmpad.asm fasmpad.o
flat assembler version 1.43
3 passes, 1942 bytes.
gcc `gtk-config --cflags --libs` fasmpad.o -o fasmpad
bazik@exodus fasmpad $ ./fasmpad
Segmentation fault
bazik@exodus fasmpad $ gdb fasmpad
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) run
Starting program: /home/bazik/MyFiles/development/fasmpad/fasmpad
Program received signal SIGSEGV, Segmentation fault.
0x40198064 in gdk_init_check () from /usr/lib/libgdk-1.2.so.0
(gdb) q
The program is running. Exit anyway? (y or n) y
bazik@exodus fasmpad $
format ELF
include 'linux.inc'
public main
GTK_WINDOW_TOPLEVEL = 0
extrn gtk_init
extrn gtk_window_new
extrn gtk_widget_set_usize
extrn gtk_window_set_title
extrn gtk_signal_connect
extrn gtk_vbox_new
extrn gtk_hbox_new
extrn gtk_text_new
extrn gtk_text_set_editable
extrn gdk_font_load
extrn gtk_vscrollbar_new
extrn gtk_box_pack_start
extrn gtk_container_add
extrn gtk_widget_show_all
extrn gtk_main
extrn gtk_button_new_with_label
extrn gtk_main_quit
extrn exit
section '.data' writeable
szCaption db "FASMPAD v0.0.1", 0
szDeleteEvent db "delete_event", 0
szDestroyEvent db "destroy", 0
szFont db "-*-fixed-*-*-*-*-*-120-*-*-*-*-*-*", 0
szSave db "Save", 0
section '.bss' writeable
nHwnd dd ?
nVbox dd ?
nHbox dd ?
nText dd ?
nFont dd ?
nVscroll dd ?
nButton dd ?
section '.text' executable
proc main, argc,argv
enter
; ccall gtk_init, [argc], [argv] ; <-- here
ccall gtk_init, 0, 0
ccall gtk_window_new, GTK_WINDOW_TOPLEVEL
mov [nHwnd], eax
ccall gtk_widget_set_usize, eax, 600, 400
ccall gtk_window_set_title, [nHwnd], szCaption
ccall gtk_signal_connect, [nHwnd], szDeleteEvent, DeleteEvent, 0
ccall gtk_signal_connect, [nHwnd], szDestroyEvent, DestroyEvent, 0
ccall gtk_vbox_new, 0, 0
mov [nVbox], eax
ccall gtk_hbox_new, 0, 0
mov [nHbox], eax
ccall gtk_text_new, 0, 0
mov [nText], eax
ccall gtk_text_set_editable, [nText], 1
ccall gdk_font_load, szFont
mov [nFont], eax
ccall gtk_vscrollbar_new, [nText]
mov [nVscroll], eax
ccall gtk_box_pack_start, [nHbox], [nText], 1, 1, 0
ccall gtk_box_pack_start, [nHbox], [nVscroll], 0, 0, 0
ccall gtk_button_new_with_label, szSave
mov [nButton], eax
ccall gtk_box_pack_start, [nVbox], [nHbox], 1, 1, 0
ccall gtk_box_pack_start, [nVbox], [nButton], 0, 0, 0
ccall gtk_container_add, [nHwnd], [nVbox]
ccall gtk_widget_show_all, [nHwnd]
call gtk_main
ccall exit, 0
proc DeleteEvent
enter
xor eax,eax
return
proc DestroyEvent
enter
call gtk_main_quit
return
Makefile:
fasmpad: fasmpad.o
gcc `gtk-config --cflags --libs` fasmpad.o -o fasmpad
fasmpad.o: fasmpad.asm linux.inc
fasm fasmpad.asm fasmpad.o
Linux.inc (Privalovs ccall.inc... just renamed it ;) )
macro proc name,[arg] ; define procedure
{ common
name:
virtual at ebp+8
if ~ arg eq
forward
local ..arg
..arg dd ?
arg equ ..arg
common
end if
end virtual
local ..dynamic_data,..dynamic_size
dynamic_data equ ..dynamic_data
dynamic_size equ ..dynamic_size
virtual at ebp - dynamic_size
dynamic_data: }
macro enter ; begin procedure instructions
{ dynamic_size = $ - dynamic_data
end virtual
enter dynamic_size,0 }
macro return ; return from procedure
{ leave
ret }
macro ccall proc,[arg] ; call procedure
{ common local size
size = 0
reverse
push arg
size = size+4
common
call proc
add esp,size }
Screenshot for all interested (I said its simple... well more minimalstic) ;)
I'm not very familiar with fasm and not at all with linux programming but doesn't gtk_init need its parameters by reference? It seems like you are passing the values of argc and argv to it while you should pass the addresses of them both :confused:
Thomas
Thomas
I'm not very familiar with fasm and not at all with linux programming but doesn't gtk_init need its parameters by reference? It seems like you are passing the values of argc and argv to it while you should pass the addresses of them both :confused:
Thomas
Thanks Thomas but I didnt get it working :/
The C declaration for gtk_init :
void gtk_init (int *argc,
char ***argv);
I got it to work!!! (At least I think so...) :)
seems to work too, no segment fault. I think a bove three lines work, I tried to pass "--display --sync -gtk-debug" to the app and I got "Gtk-WARNING **: cannot open display: --sync".
When playing around a little i made this (see attachment), it sets the app caption to argv[0]. I made that and then realized how I could do.
N.B! The file is a .tgz archive!
lea eax, [ebp+12]
lea ebx, [ebp+8]
call gtk_init, ebx, eax
seems to work too, no segment fault. I think a bove three lines work, I tried to pass "--display --sync -gtk-debug" to the app and I got "Gtk-WARNING **: cannot open display: --sync".
When playing around a little i made this (see attachment), it sets the app caption to argv[0]. I made that and then realized how I could do.
N.B! The file is a .tgz archive!
gtk_init needs the pointers to your argc and argv arguments, not the arguments themselves, because it needs to modify them, because it needs to remove argument that it has interpreted.
Here's my working version.
Here's my working version.
gtk_init needs the pointers to your argc and argv arguments, not the arguments themselves, because it needs to modify them, because it needs to remove argument that it has interpreted.
Here's my working version.
Thanks a lot Privalov :alright:
I should refresh my C knowledge ;)
BTW assembly programs like out gtk/gnome examples are very strange - only moves and calls. Could we call it true assembly?
BTW assembly programs like out gtk/gnome examples are very strange - only moves and calls. Could we call it true assembly?
A windows programm with just a GUI will look the same ;)
There will be some "true assembly" in it when I wrote some functions behind the GUI :P
Already extended the above code with a File/Edit/Format/Help menu and a statusbar. I'll just write a small "Notepad"-Clone in FASM for training ;)
Think like file reading/saving will happen through kernel interrups (using C functions would make it too easy :P )
It would be nice to put it then in the "examples" section of fasm website, if you allow. So there would be also some example for Linux (only DOS and Windows examples now).
Think like file reading/saving will happen through kernel interrups (using C functions would make it too easy :P )
No, the kernel interrupts are the ones easier to use. Especially when you've been learning assembly in DOS (like me).
Think like file reading/saving will happen through kernel interrups (using C functions would make it too easy :P )
No, the kernel interrupts are the ones easier to use. Especially when you've been learning assembly in DOS (like me).
This maybe a bit oftopic but yet realted (since I've seen thins that look like classes, at lest if you just look at the names, eg GtkContainerClass), what diiffers a structure form a class?
And does classes exist in C or did they arrive in C++?
I Think I might just have to google for some C-programming books this weekend and learn some C, somehow I think I'm gonna need it...
And does classes exist in C or did they arrive in C++?
I Think I might just have to google for some C-programming books this weekend and learn some C, somehow I think I'm gonna need it...