Gaurav Agarwal | 20 Aug 08:33 2014
Picon

gdb weirdness with a toy go program

Hi all,


I'm playing with using gdb to debug go programs. Unfortunately, I'm running into problems where I cannot seem to get information about local variables from gdb. Can someone pls point out what am I doing wrong:

Go Code (debug.go)
package main

import (
"fmt"
)

func main() {
var i int = 10
pi := &i
fmt.Printf("i=%d &i=%p pi=%p *pi=%d\n", i, &i, pi, *pi)
fmt.Println("done")
}

Compilation

go build -gcflags "-N -l" debug.go


GDB
L-IDC10GDKQ2-M:pointers gagarw1$ gdb debug
GNU gdb (GDB) 7.7.1
This GDB was configured as "x86_64-apple-darwin13.2.0".
Reading symbols from debug...done.
warning: Missing auto-load scripts referenced in section .debug_gdb_scripts
of file /Users/gagarw1/workspace/go/src/practice/pointers/debug
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) l
1 package main
2
3 import (
4 "fmt"
5 )
6
7 func main() {
8 var i int = 10
9 pi := &i
10 fmt.Printf("i=%d &i=%p pi=%p *pi=%d\n", i, &i, pi, *pi)
(gdb) b 10
Breakpoint 1 at 0x205a: file /Users/gagarw1/workspace/go/src/practice/pointers/debug.go, line 10.
(gdb) r
Starting program: /Users/gagarw1/workspace/go/src/practice/pointers/debug 
[New Thread 0x170b of process 33511]
Breakpoint 1, main.main () at /Users/gagarw1/workspace/go/src/practice/pointers/debug.go:10
10 fmt.Printf("i=%d &i=%p pi=%p *pi=%d\n", i, &i, pi, *pi)
(gdb) info locals
pi = 0x6
&i = 0x6
(gdb) p pi 
$1 = (int *) 0x6
(gdb) p i
No symbol "i" in current context.

Note that variable i is not accessible, and the pointer values seem to be stack offsets instead of an absolute address. Then there is an unexpected '&i' variable being shown by debugger.

Is there some additional flag I need to pass to go command to get the proper variable inspection from gdb?

--cheers, gaurav

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
John Clover | 20 Aug 06:21 2014
Picon

Let's build a browser engine blog posts

Hey, I was wondering if any other Go nuts have read these posts and written up the engine in Go.

I've been working on it a bit here: https://github.com/radiofreejohn/gobinson but I'd really like to see
what others have done since 1) I don't know Rust and 2) I am not that great at Go :)

Posts are here: http://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html

Matt's repo is here: https://github.com/mbrubeck/robinson

--

-- 
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@...
For more options, visit https://groups.google.com/d/optout.

Audrey Lim | 20 Aug 05:09 2014
Picon

Loop through >> person.Posts = []*Post{&a[0], &a[1]}

I have the code here: http://play.golang.org/p/x98WYdjJb2

How do I insert the value of a[0], a[1], with a variable a[i] in line 57? These are variables that are created at runtime.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
tgrosinger | 19 Aug 23:49 2014

Cover report in multiple packages

I have an application with a few packages, and unit tests mostly located in just one package. For example:

A -> B -> C

My unit tests run against the code in package A which depends on package B which depends on package C. When running with "-cover" I only get a report of the coverage in package A. Is there a way to get the coverage report for all the packages in the project based on the tests that are run?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Dave Cheney | 20 Aug 04:46 2014
Picon

Re: Re: Crashing without messages - how do I debug?


Why bother running the function in another goroutine when the caller waits for it to finish? That isn't really concurrency. 


On 20 Aug 2014, at 12:42, Tom Maiaroto <tom.maiaroto <at> gmail.com> wrote:

I mean, I'm going to try to follow this http://www.acloudtree.com/how-to-shove-data-into-postgres-using-goroutinesgophers-and-golang/  ... best i can ... though i do need to analyze the data before inserting. perhaps waiting on hundreds of http requests is the issue?

On Tuesday, August 19, 2014 9:37:08 PM UTC-5, Tom Maiaroto wrote:
It's an RDS Postgres micro... Is that not going to be fast enough? It's only a couple hundred inserts every few minutes. Each of which gets some parsing and analyzing. I use another service across HTTP to get data like geolocation and then save to the database. So I imagine inserts should be somewhat staggered and not 200 every second... Even still, if that was the case, isn't that manageable?

Again, I guess I'm at a loss for finding good examples of how to handle high insert volume. If I dial with a timeout, do you suspect that there will be timeouts in this case then? And if so, I just lose the data? Hmmm


On Tuesday, August 19, 2014 4:54:29 PM UTC-5, Dave Cheney wrote:
I think the database angle is a false positive.

I suspect you're dialing without a timeout, so a slow remote server will cause the number of goroutines to increase with time and you'll get killed by the OOM killer.

On Wednesday, 20 August 2014 05:52:56 UTC+10, Tom Maiaroto wrote:
I see a lot of:

goroutine 10723 [select]: net/http.(*persistConn).readLoop(0xc208605ce0) /usr/local/go/src/pkg/net/http/transport.go:868 +0x829 created by net/http.(*Transport).dialConn /usr/local/go/src/pkg/net/http/transport.go:600 +0x93f goroutine 10845 [chan receive]: database/sql.(*DB).connectionOpener(0xc208446d80) /usr/local/go/src/pkg/database/sql/sql.go:583 +0x48 created by database/sql.Open /usr/local/go/src/pkg/database/sql/sql.go:442 +0x27c goroutine 10724 [select]: net/http.(*persistConn).writeLoop(0xc208605ce0) /usr/local/go/src/pkg/net/http/transport.go:885 +0x38f created by net/http.(*Transport).dialConn /usr/local/go/src/pkg/net/http/transport.go:601 +0x957

... 

I read somewhere to insert a lot of rows I'd have to wrap a function in a goroutine and pass it a new connection


I'm wondering if this was incorrect advice... Or maybe only applied to certain database drivers...
Basically I call StoreRow() in this case, from a variety of places (and in a loop with hundreds of results) like so:


...looking at my comments, I just seem to have a lot of questions around best practices for the process of shoving as much data into a database as quickly as possible.



On Tuesday, August 19, 2014 2:43:58 PM UTC-5, James Bardin wrote:

On Tue, Aug 19, 2014 at 3:12 PM, Tom Maiaroto <tom.ma... <at> gmail.com> wrote:
yea, i've clicked them and look at them a bit. i just don't know what to look for. what would indicate a process i really need to ensure is returned or something. what the most expensive ones were, etc.
so those numbers do decrease then?

There's probably a large numbers of goroutines in the same blocks of code, which would give you a hint as to where they're coming from.

Goroutines act just like function calls, and they need to return to free their resources. If you start a goroutine and it gets blocked somewhere, those resources are never going to be freed. Remember that many things have inherent concurrency -- every request you handle with the http.Server starts at least one goroutine, so does every request with http.Client.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/eBMuzJxaeno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Jeff | 20 Aug 03:21 2014

Package / directory structure for web server

Hi all, I'm new to Golang and had some questions about how to structure the packages in a web server with a Mongo backend.  I originally started with a monolithic package but that doesn't do a good job of separating out the concerns of the code (i.e. query logic is in same method as business logic).

I have begun moving to a structure with 4 packages, models, queriers, services, and handlers, which are divide as follows:

Models: just the structs the mirror the contents in the database
Queriers: equivalent to a DAO layer in other frameworks, just has the code for making queries to mongo using mgo.  Allows for easy mocking for testing.
Services: business logic
Handlers: contains the http handler functions and performs any changes to the data to make them compatible with the client (i.e. converting int to string, or return "not logged in"

But now I am thinking it may be better to instead structure the packages more by function, such that there would be a single "users" package that would contain the user model, querier, service, and handler.  This would certainly save me from having to write a lot of "models.User" in all of my queriers because the user querier would be in the same package as the user model.  

I am wondering if anyone with more experience with Golang has any thoughts on either approach, or I am open to other ways to structure the code of a web server.

Thanks!
Jeff
 
 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
stpra123 | 20 Aug 02:26 2014
Picon

Go w/ Python typing

I am a complete newb to Go but am attracted to the speed it offers vs. Python. I am in a bind in that I would LOVE to learn Go & use if for a lot of future projects I have in mind but I really hate the static type of the language....it just gives me a headache to even look at it. On the other hand, I really like the syntax of Python but it is slow.

My question is (and, keep in mind I haven't delved deeply into Go and I don't have any experience of working under the hood of either language): is it possible to fork Go and make it dynamically typed? Basically, you'd have the beauty of Python and the speed of Go. Call it GoPy or PyGo.

(I do realize this might be the newb question of the year so please feel free to chuckle ;). I also realize there's probably many others in my same situation.)

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Gerard | 20 Aug 02:22 2014
Picon

MINIX 3 platform support?

Hello everybody,

I wonder if MINIX 3 will be supported by Go. I am aware that the platform is not high profile, but 3.3 looks really interesting.

Just wondering.

Gerard

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Eric Johnson | 20 Aug 01:00 2014

Good database utility library

I'm looking for a go library that already does the SQL utility methods I find myself writing.

Specifically, I've got methods like:
  • Transaction - calls a function to perform actions in a transaction, and then commits or rolls back based on the error returned from the function.
  • MustPrepare - similar to the regexp.MustCompile(), in that it prepares a statement that must be valid, or a panic ensues.
  • MultiExec - Executes multiple statements (with no parameters) in a row. Returns an error on the first failure.
I tried searching for such a library but go-search yields too many results to easily sift through, so I'm hoping that crowd-sourcing the question will yield better results.

I found sqlx, but that seems to be far more complicated than I need.

Eric.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Keyur Shah | 20 Aug 00:03 2014
Picon

range and pointers

Consider the following code: (shared here: http://play.golang.org/p/mAQSEEU6i_)

func main() {
foos := []Foo{Foo{v: 1}, Foo{v: 2}}

foos2 := make([]*Foo, 0)
for _, f := range foos {
foos2 = append(foos2, &f)
}
fmt.Println(foos2[0].v, foos2[1].v)
}

type Foo struct {v int}

---

It may be my shallow understanding of Go, but I was expecting this program to print "1 2". However it prints "2 2". This tells me that Go maintains a single pointer and reuses the same pointer to reference each element in the loop. Is that a correct interpretation?

This is what I did to get it working the way I wanted:

foos3 := make([]*Foo, 0)
for _, f := range foos {
f2 := f
foos3 = append(foos3, &f2)
}
fmt.Println(foos3[0].v, foos3[1].v)

Is there a better / idiomatic approach?

== Keyur

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
John Song | 19 Aug 05:48 2014
Picon

groupcache peer discovery based on group name

Hi,

I am adding peer auto discovery mechanism to groupcache using ZK. I am curious why in groupcache.go the following function is private.

func newGroup(name string, cacheBytes int64, getter Getter, peers PeerPicker) *Group

In my cases, each group represent one type of data to cache. Not all peers need all groups. E.g, we have 10 servers, 1 - 5 may have groupA, 6 - 10 have groupB, and 1,3,5,7,9 may have groupC. Had the above func be public, I can support my own PeerPicker based on the group name and only store cache on servers that are within the same group.

Group discovery is easily achievable through Zookeeper's membership functions. Thus, it is easy for me to implement a PeerPicker that leverage this info.

However, it seems to me that the above newGroup func has been changed to private during open source of groupcache. 

I have looked through groupcache code, and it seems to be that except forking groupchache and make the above newGroup func public there is nothing getting around to implement a PeerPicker by group membership.

Thanks,

-John Song

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane