Re: argv



Mr. Robinson,

My original email was verbose so it never made it to the mailing list so
I decided to send it directly to you.  I didn't realize you're were
going to be upset with the entire community because of my answer.
There was no condescending or tone of superiority ever conveyed in that
email although I am speaking from THOROUGH experience with variety of
languages and a variety of operating systems.  With that experience I
actually meant to save you time NOT WASTE IT.

Let me highlight again what I thought was useful from my email that
perhaps you didn't catch:
https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/multithread

Here is the Makefile for MSYS2. It should work for both 32-bit and
64-bit msys2 shells. The "make -B" build all output that follows is from
the 32-bit MSYS2 shell and should answer any questions about the
environment you have. If you compile with the -S switch as stated
before, it should also answer all your questions about the arguments you
have also.

$ more Makefile
MYGCC = g++ -v -std=gnu++11
MYCOMPILESWITCHES = `pkg-config gtkmm-3.0 --cflags`
MYLIBSWITCHES = -L /mingw64/lib -lboost_system-mt -lboost_filesystem-mt
-lboost_serialization-mt -lboost_iostreams-mt -lboost_date_time-mt
`pkg-config gtkmm-3.0 --libs`

all: gtkmm_multithread

gtkmm_multithread : exampleworker.h examplewindow.h exampleworker.cc
examplewindow.cc main.cc
${MYGCC} $(MYCOMPILESWITCHES) -c exampleworker.cc -o exampleworker.o
$(MYLIBSWITCHES)
${MYGCC} $(MYCOMPILESWITCHES) -c examplewindow.cc -o examplewindow.o
$(MYLIBSWITCHES)
${MYGCC} $(MYCOMPILESWITCHES) -c main.cc -o main.o $(MYLIBSWITCHES)
${MYGCC} $(MYCOMPILESWITCHES) -o gtkmm_multithread main.o
examplewindow.o exampleworker.o $(MYLIBSWITCHES)


make -B

This examples compiles within the 32-bit msys2 shell.  That will
probably be more in line with where you want to be for you win32
compatibility.

After building it successfully, I mentioned "gcc -c -S" or "g++ -c -S"
generates the assembler, but someone else here nudged you even closer to
your goal with "gcc -c -S -masm=intel" to generate the nasm/masm syntax
rather than the default AT&T syntax. That "gcc -c -S -masm=intel" output
will answer your original question.

KEEP IN MIND it also compiles from within the 64-bit MSys shell. I will
restate that 32-bit hardware is getting old and 32-bit operating systems
are deprecated for a few good reasons:
-large files(>4GBytes) bug out on 32-bit operating systems in certain areas
-year 2000 residue bugs to do with low-level uuid/COM/DCOM bugs are
coming and the recommended transition to non-32-bit OS has passed to
mitigate that.
-physical flat memory limitations of 32-bit OS no longer satisfy many
real-world application requirements and all the techniques used earlier
to virtually surpass those limitations have long been considered kludge
patches rendering the long-term maintenance of code unnecessarily
complex and ugly.  The bottom line:  it's not fun to code 32-bit code
for server apps or any desktop/workstation app that requires very large
amounts of data.  The trendy machine learning stuff falls into the very
large amount of data for example.  Machine-learning code would probably
spend as much time swizzling pointers as processing data on a 32-bit OS.
 I'm sure some computer scientists could debate that I am exaggerating,
but there is time wasted on operations you would not see on a 64-bit or
128-bit OS.
I'm sure any new os could emulate your win32 app, but the suggestion
still remains: you should seriously consider moving your code to a
64-bit language on a 64-bit OS.  I never forced anything here down your
throat.  It's your life after all.  If you prefer the synergy that
Microsoft emanates and go for it, but in my entire life as a coder I
have seen more synergy evolve from the GNU/Linux community of which the
GTK community is a part of.  On the contrary for Microsoft, here are a
few examples of how Microsoft has extinguished different communities
over time:
1)Older Microsoft Extinguish example On-The-Fly Compression.
DoubleSpace was integrated into Microsoft product and it essentially
killed the market for disk compression offerings DoubleDisk, Stacker,
SuperStor and Expanz! Plus.
2)Web Browsers/Web Server Product market:
Internet Explorer was introduced into the OS and it killed Netscape's
ability to sell Web-Browser/Web Server product.  This action was not so
subtle and came much later.
3)Microsoft J++ extending java to attempt to kill Java
This attempt failed because of government intervention since Sun/Oracle
brought Microsoft to court over these matters.  The original MS
agreement was not to tamper with the JAVA API which Microsoft in fact
did in very subtle ways.
4)XAMARIN BOUGHT BY MICROSOFT AND ROBOVM DISCONTINUED:
http://www.theregister.co.uk/2016/04/15/microsoft_discontinues_robovm/
Microsoft is desperately attempting to sell mobile devices with MS
operating system on it in order to gain the royalties from that
entirely.  It is much harder from them when Google's Android/Linux is
provided as open-source placing all the manufacturers at a level-playing
field without falling under the iron-grip of secret OEM agreements with
Microsoft.  Recently it has been discussed that is still the case with
certain companies attempting to evade lawsuits with Microsoft when using
Android they still need to pay Microsoft for some licensing fees for
parts of Android.

These are but a few examples of the so-called "Microsoft community" that
crush anyone outside of it.  The idea of learning stuff under-the-hood
and "do-it-yourself" with Microsoft product is an illusion.  What
technology Microsoft deems core, you will never have the privilege to
have your eyes on that. I won't recommend you to change, but I needed to
answer to your perception that the Microsoft community is supportive
when in fact it is subtly only looking to preserve its piece of the
larger profit pies.  It has slowly expanded from operating systems(dos
to windows) to office productivity(office, office365), gaming
consoles(xbox), mobile devices(surface),  desktop accessories(mice and
keyboards) and now 3D stuff.  When it does expand, it leaves no room for
competitors; it crushes them.  The only opponent it has never succeeded
in crushing is GNU/Linux because as others on this mailing list have
pointed out this is a community of volunteers, conscientious volunteers,
trying to help others, without any regard for $$$profit.  When you leave
government and companies make decisions solely on profit, they end up in
crisis management situations rather than being in mature preventive
environments.  Decisions made in free and open-source communities are
based on the right thing to do and not based on profit.  They're not
perfect code-bases, but since they are open, they can be improved by
those who can when they are ready when they reach that phase in their
lives where it becomes a priority for them to contribute to open-source
in whatever way they can.  The stuff out in GNU/Linux now for doing
daily stuff is good enough your grandma can use it.  That means we don't
need Microsoft anymore for anything which means no more profit for
Microsoft.  Microsoft will eventually cease to exist because their
purpose is not to contribute to society but to make profit.  These two
values are ultimately in conflict with each other.  You choose which
value is most important for you.  You may choose to become a purist
profiteer or not or a compromise somewhere in the middle.  Life is
complicated so at times we are purist and at times we are not.

Don't see this as condescending.  See this as clarifying of my
perspective that I believe GNU/Linux better reflects the global
consciousness and the direction we want the world to go towards.  I make
these suggestions towards more GNU/Linux and less Microsoft, but in no
way did I ever impose anything.  Just keep these things in mind when you
reflect and make your decisions along the way.

Sincerely,
David Marceau
http://adequatech.ca


On 04/12/2016 07:58 AM, David Marceau 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







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]