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

Reply via email to