1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.debugger.linux;
  26 
  27 import sun.jvm.hotspot.debugger.*;
  28 
  29 class LinuxThread implements ThreadProxy {
  30     private LinuxDebugger debugger;
  31     private int           lwp_id;
  32 
  33     /** The address argument must be the address of the _thread_id in the
  34         OSThread. It's value is result ::gettid() call. */
  35     LinuxThread(LinuxDebugger debugger, Address addr) {
  36         this.debugger = debugger;
  37         // FIXME: size of data fetched here should be configurable.
  38         // However, making it so would produce a dependency on the "types"
  39         // package from the debugger package, which is not desired.
  40         int pid = (int)addr.getCIntegerAt(0, 4, true);
  41         if (debugger instanceof LinuxDebuggerLocal) {
  42             int hostPID = ((LinuxDebuggerLocal)debugger).getHostPID(pid);
  43             if (hostPID != -1) {
  44                 pid = hostPID;
  45             }
  46         }
  47         this.lwp_id = pid;
  48 
  49     }
  50 
  51     LinuxThread(LinuxDebugger debugger, long id) {
  52         this.debugger = debugger;
  53         this.lwp_id = (int) id;
  54     }
  55 
  56     public boolean equals(Object obj) {
  57         if ((obj == null) || !(obj instanceof LinuxThread)) {
  58             return false;
  59         }
  60 
  61         return (((LinuxThread) obj).lwp_id == lwp_id);
  62     }
  63 
  64     public int hashCode() {
  65         return lwp_id;
  66     }
  67 
  68     public String toString() {
  69         return Integer.toString(lwp_id);
  70     }
  71 
  72     public ThreadContext getContext() throws IllegalThreadStateException {
  73         long[] data = debugger.getThreadIntegerRegisterSet(lwp_id);
  74         ThreadContext context = LinuxThreadContextFactory.createThreadContext(debugger);
  75         for (int i = 0; i < data.length; i++) {
  76             context.setRegister(i, data[i]);
  77         }
  78         return context;
  79     }
  80 
  81     public boolean canSetContext() throws DebuggerException {
  82         return false;
  83     }
  84 
  85     public void setContext(ThreadContext context)
  86       throws IllegalThreadStateException, DebuggerException {
  87         throw new DebuggerException("Unimplemented");
  88     }
  89 }