Hi David,

Yes I use gtk_init(), since it is impossible to run any GTK application
without it (or at least one of it's alternatives). I have a complete working
application but when I tried making a simple modification to the source to
read the command line, it won't work and I can't figure out why.

We both interpret the documentation for gtk_init() the same way, namely that
argc and argv exist before and after gtk_init(), the only difference being
that gtk_init() strips out only the GTK command arguments from the command
line, leaving the rest of the arguments alone. In my case, since I am not
passing any GTK specific commands, argc and argv should remain untouched by
gtk_init(). In both cases, argc and argv do not contain any data that makes
sense.

I didn't compile my own version of the GTK runtime libraries, since the GTK
project doesn't support providing precompiled runtime binaries for Gtk+3 Win32
or Win64. I am looking for a simple plug-and-play solution to my current
project therefore I didn't want to start yet another project in order to
create my own GTK runtime binaries, so I "borrowed" the only ones I could find
from the GtkD project. There is nothing wrong with doing that, is there?

I looked at your example below and I notice many peculiar things about it:

1) It uses the 64-bit Linux libraries whereas I am using the 32-bit Win
libraries
2) GCC assembly language sucks :^)
3) Despite #2 above, I noticed something very peculiar about the disassembly
code. For argv, GCC uses a 32-bit register, whereas for the argc, GCC uses a
64-bit register. This isn't documented anywhere. Does this apply to 32-bit Win
code as well, i.e. -- argv would use a 32-bit register and argc would use a
16-bit register? This disassembly example violates the 64-bit code convention
used by the C standard and by the Win and Linux OSes as well.
4) The documentation implies argc and argv are consecutive parameters, yet
they are not consecutive in the disassembly. One has an offset of 32 and the
other of 20, when they should be 24 and 32. This too isn't documented anywhere
but apparently has something to do with #3 above. This could be my problem so
I will try different offsets to the stack to see what it returns.
5) It uses the Gtk+2 libraries whereas I am using Gtk+3. It appears that the
Gtk+2 libraries pass parameters in the registers and there is no stack
cleanup, whereas the Gtk+3 libraries pass parameters on the stack and stack
cleanup is required. Again, not documented. This may not matter unless I
wanted to convert my application later on to 64-bit, so this is good to know
beforehand.

Live long and prosper,
Andrew

On 4/12/2016 at 4:58 AM, David Marceau <uticdmarceau2...@yahoo.ca> wrote:
>Taken from an older gtk tutorial, but nevertheless should apply to your
>situation:
>http://www.gtk.org/tutorial1.2/gtk_tut-2.html
>
>#include <gtk/gtk.h>
>
>int main( int   argc,
>          char *argv[] )
>{
>    GtkWidget *window;
>
>    //<<<<<<<<<<<<<<<<<<<<<<<<<<<
>    //DID YOU INTRODUCE THIS LINE IN YOUR CODE?
>    gtk_init (&argc, &argv);
>    //>>>>>>>>>>>>>>>>>>>>>>>>>
>
>    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>    gtk_widget_show  (window);
>
>    gtk_main ();
>
>    return(0);
>}
>
>
>"Here is our gtk_init again. As before, this initializes the toolkit,
>and parses the arguments found on the command line. Any argument it
>recognizes from the command line, it removes from the list, and modifies
>argc and argv to make it look like they never existed, allowing your
>application to parse the remaining arguments.
>
>       gtk_init (&argc, &argv);
>"
>
>DID YOU CATCH THAT LAST PART?  It grabs any arguments that are gtk
>specific and removes them.  The leftover arguments are left within the
>argv array.  Did you call gtk_init?  Did you pass any non-GTK-switch
>arguments to your app?  If not, it would explain why your argsv holds
>empty/uninitialized values.
>
>If you really need to resort to assembler, just run the gcc/g++ compiler
>with the "-c -S" to generate the assembler to see how they gcc compiler
>does it with the above gtkhello.c
>
>THIS IS THE ENVIRONMENT SETUP ON DEBIAN LINUX:
>pkg-config --cflags --libs gtk+-2.0
>
>-pthread -I/usr/include/gtk-2.0
>-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/
>-I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0
>-I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libpng12
>-I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12
>-I/usr/include/pango-1.0 -I/usr/include/harfbuzz
>-I/usr/include/pango-1.0 -I/usr/include/glib-2.0
>-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2
>-lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo
>-lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0
>-lglib-2.0 -lfontconfig -lfreetype
>
>THIS IS TO COMPILE THE ABOVE GTKHELLO
>gcc gtkhello.c `pkg-config --cflags --libs gtk+-2.0`
>
>THIS IS TO GENERATE THE ASSEMBLER FOR GTKHELLO
>gcc -S gtkhello.c `pkg-config --cflags --libs gtk+-2.0`
>
>cat gtkhello.s
>       .file   "gtkhello.c"
>       .text
>       .globl  main
>       .type   main, @function
>main:
>.LFB206:
>       .cfi_startproc
>       pushq   %rbp
>       .cfi_def_cfa_offset 16
>       .cfi_offset 6, -16
>       movq    %rsp, %rbp
>       .cfi_def_cfa_register 6
>       subq    $32, %rsp
>       movl    %edi, -20(%rbp)
>       movq    %rsi, -32(%rbp)
>       leaq    -32(%rbp), %rdx
>       leaq    -20(%rbp), %rax
>       movq    %rdx, %rsi
>       movq    %rax, %rdi
>       call    gtk_init
>       movl    $0, %edi
>       call    gtk_window_new
>       movq    %rax, -8(%rbp)
>       movq    -8(%rbp), %rax
>       movq    %rax, %rdi
>       call    gtk_widget_show
>       call    gtk_main
>       movl    $0, %eax
>       leave
>       .cfi_def_cfa 7, 8
>       ret
>       .cfi_endproc
>.LFE206:
>       .size   main, .-main
>       .ident  "GCC: (Debian 5.3.1-14) 5.3.1 20160409"
>       .section        .note.GNU-stack,"",@progbits
>
>
>
>Cheers,
>David Marceau
>
>
>
>On 04/09/2016 09:39 PM, Andrew Robinson wrote:
>> This should be easy, but it is not. I am writing an assembly language
program
>> involving GTK+. I want to parse the command line for options but am unable
to
>> do so. The code to find argv and argc is simple:
>> 
>> main:
>>    push ebp
>>    mov ebp, esp
>>    lea eax, [ebp + 12]
>>    lea ecx, [ebp + 8]
>> 
>> The problem is that [ebp + 12] and [ebp + 8] point to nonsense. I ran a
>> debugger and looked at the stack, and there is nothing else on the stack
>> except for ebp, rtn addr, and these two parameters. I even tried
>> daisy-chaining the addresses to see where they would lead, and they are not
>> even close to pointing to the actual command line. I can easily find the
>> command line using a memory search, so I know what address it should be.
What
>> am I doing wrong here? I have:
>> 
>> Gtk3+
>> Win32
>> v3.18.3.0
>> _______________________________________________
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>> 
>
>_______________________________________________
>gtk-app-devel-list mailing list
>gtk-app-devel-list@gnome.org
>https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to